Sunday, March 3, 2013

Upgrading Python on Centos 6.3

In recent weeks I have become quite a fan of Python. Just like in many other cases, I learn to appreciate something once I have to use it. The attraction to Python is partly due to the sheer number of available libraries and packages. It seems like for virtually any task someone has already posted the 10-lines of python code to do it.

The majority of my computers run Centos 5.5 and Centos 6.3. Yes, there are some advantages in running Centos, and there are some good reasons not to upgrade a fine-tuned, running system. But Centos shows its conservative side with respect to the versions of its packages: Python 2.4.3 on Centos 5.5, and Python 2.6.6 on Centos 6.3.

Unfortunately, a number of software packages utilize Python, and many of them don't seem to be to friendly to the older versions. Even if most of my scripting would work on the older versions, those packages forced the upgrade.

The installation of newer versions is not that difficult. Fortunately, one can maintain several different version on the same system.

The blog http://toomuchdata.com/2012/06/25/how-to-install-python-2-7-3-on-centos-6-2/ describes how to download and install different versions quite nicely.

I choose /usr/local/Python-2.7.3 and /usr/local/Python-3.3.0 as the new locations. Fortunately, most of the work is done by running:
 
$ ./configure --prefix=/usr/local/Python-2.7.3
$ make
$ make install

Each Python installation has it's own directory for packages:
/usr/local/Python-2.7.3/lib/python2.7/site-packages/
That means one has to re-install all the packages that are needed. A significant advantage of separate installation directories is, of course, that different versions don't interfere with each other. Certain packages may not be compatible to all versions, either.

For users to select their Python version I created simple module files like this one:

#%Module1.0#####################################################################
##
proc ModulesHelp { } {
        global dotversion

        puts stderr "\tSelects Python 2.7.3"
        puts stderr "\n\tUse `python'."
        puts stderr "\n\t(PM 2013-02-15)\n"
}
module-whatis   "sets Python 2.7.3 as default interpreter
prepend-path    PATH    /usr/local/Python-2.7.3/bin/

All it takes is to set the PATH environment variable, though, there might be some other variables that should be defined.

2 comments:

Anonymous said...

installing python 2.7.3 on RHEL 6.3 with make install will break yum.

i suggest -> make altinstall

plasticca said...

Yes my yum was broken when i upgraded from 2.6.6 to 2.7.5. The machine is a centos. CUrrently repairing the same