Alt-Installing Python 2.6 from source in CentOS

I work with some smart folks who need the latest stuff to get the job done. However, this can sometimes be a problem when you use a more conservative (read: stable) Linux distribution like CentOS.

You see, CentOS 5 comes bundled with Python 2.4 where Fedora or Ubuntu (or Linux Mint) ship with Python 2.6.

(nathan@citadel:~)$ cat /etc/issue
Linux Mint 9 Gloria - Main Edition \n \l
(nathan@citadel:~)$ python
Python 2.6.4 (r264:75706, Dec  7 2009, 18:45:15)
(nathan@test1:~)$ cat /etc/issue
CentOS release 5.5 (Final)
(nathan@test1:~)$ python
Python 2.4.3 (#1, Sep  3 2009, 15:37:37)

CentOS has several subsystems (like yum) and a whole pool of packages which expect and rely on Python 2.4 to be installed.  I’d really hate to mess with that, so when Outbrain‘s braintrust (har har) says they need a particular functionality from Python 2.6 I choose to alt-install thus:

yum -y install gcc
wget http://python.org/ftp/python/2.6.4/Python-2.6.4.tgz
tar zxvf Python-2.6.5.tgz -C /usr/src && cd /usr/src/Python-2.6.5
./configure
make
make altinstall

Easy, huh?

So, 2.4 is the default, remember?

(nathan@test1:~)$ python
Python 2.4.3 (#1, Sep  3 2009, 15:37:37)

But if you want 2.6, you need to explicitly define the 2.6 binary:

(nathan@test1:~)$ python2.6
Python 2.6.4 (r264:75706, Feb 23 2010, 10:34:37)

This means if you want your script to run 2.6 you need to change your magic from

#!/usr/bin/env python

to

#!/usr/bin/env python2.6

Et voilà!

Share
  • Captain

    Hi Nathan,

    Very instructive tutorial, unfortunately I get stuck at item…
    ========================================================
    [root@nc4u ~]# rpm -Uvh /usr/src/redhat/RPMS/x86_64/python26-2.6-geekymedia1.x86_64.rpm
    error: Failed dependencies:
    libpython2.6.so.1.0()(64bit) is needed by python26-2.6-geekymedia1.x86_64
    [root@nc4u ~]#
    ========================================================
    Have tried many times, and I can find the file somewhere else on the server, but don’t know where to put it so that I can get past this obstacle.

    Would really appreciate your input, as this python thing has totally stumped me. I’d like to install the eyeOS application which requires python 2.5.0 ->, and as you know I have python 2.4.3 with this OS, which needs to stay intact.

    Server is a Cloud at 1&1 with CentOS 5 with Plesk 9.5.2 (64-Bit), Red Hat 4.1.2-46)] on linux2,

    Appreciatively,
    Captain

    • http://twitter.com/marcosluis2186 Marcos Ortiz

      You can use the yum provides command to find which is the package that make reference to that library. Regards

      • Andy

        Can you explain a little more about the yum? I have the same issue. I want to install eyos 2 on 1and1 and I really get stuck. I have installed version 2.7.1 and Eyeos keeps on recognizing Python version 2.4.

  • http://twitter.com/marcosluis2186 Marcos Ortiz

    An excellent and easy way to have the two versions. Very useful. Thanks for sharing

  • Krank21

    Wow thanks so much! I have an older server and was in the process of installing Nodejs. You made it happen, didn’t want to mess anything up and was able to run python2.6 ./configure

  • Benny Iskandar

    Crash the system after done the installation.