Search This Blog

Thursday 10 April 2014

How to install Python2.7 in linux machines ?

Installing Python in windows is just one click matter. Since we do not have any binaries for Linux machines. it is complicated than windows installation.
for this, we have some sort of process which is easy way to install in Linux machines irrespective of flavours.

Before processing with installation process, please download Python tarball  file from official website. if you do not found link, please click here.

Once you got the tarball file, please untar the file by using following command:

$ tar xzf Python-2.7.2.tgz
$ cd python-2.7.2


Before starting installation process, we have configure our Python with system as per our system dependences.
for these, type the following command

$./confure 

By this, Python will configure all the required system dependencies to the machine.

By using 'make' command, we have to compile the source code of Python but it will compile python for /usr/local/ which requires root permission. To install in our selected directory, please follow the following command:

$make altinstall prefix=~/usr/local exec-prefix=~/usr/local

By this command, python source file will be compiled to <home directory>/usr/local folder. at this moment, user may get the following warning which is causing a break point of your installation process




To avoid these "clock skew detected " warnings, simply retype the above "make" command untill you get modified time to 0.00

there is an another process to avoid these kind of warnings.
to remove these warnings, in Linux, we have "touch" command which simply changes the time stamp of the provided file to system time

$ touch <filename>

or else, you can change system date using following command :
$ sudo date <mmddhhmnyyyy>

where mm-month in 01-12 format
          dd-date of the month
          hh-hour of the current time, which should be 24 hours format
          mn-minutes
          yyyy- year

Another way to install property and remove above error is,
Just 'cd' into the directory where the files need a time-stamp update.
             Next use the following command which will update the time-stamps of all the files in the   directory:
      
          $find . -exec touch {} \;

once you have enter this command, it will try to modify entire files time stamp in provided folder. after this, once again run 'make' command. this time it will run successfully without errors warnings.

Ok, till now went good, bu as you already know, every Linux flavor comes with inbuilt python version either 2.5 or 2.6 version of python. if you have installed latest version, by entering 'python ' in terminal, it should launch your python rather than in built python. for these, we need to  link installed python to available python for making a copy for new version

$ ln -s python2.7 python

now, we need to create alias for installed python as follows:

 $alias python = '~/usr/local/bin/python'

now enter python in terminal and see the version. it will give latest version which is installed just now.
to make alias permanent, enter above alias line in .bashrc file and restart the computer for effect of configuration changes.
$vi .bashrc # enter alias in this file