Sunday, August 5, 2012

Install Python 2.7 on centos without breaking yum (which depends on 2.4)

Problem Statement:
Here's the deal. I want to be able to run the Datastax Suite on a Red Hat Enterprise Linux Server release 5.5 (Tikanga) vm or a centOS 5.x distro. Datastax has a super nice console for monitoring a Cassandra cluster(s). This web based console requires Python 2.6 or 2.7 (but not 3.x -not supported yet as of 8/5/2012). In addition to the ops console needing a newer python, cqlsh (CQL shell) bundled with Cassandra as of 0.8 requires a modern version of python as well. But the problem is we just can't blindly upgrade to Python 2.7 as there is a hard dependency on Python 2.4 for centOS and RH distros and will cause yum package manager to break. So to keep yum happy, we need versions of python 2.4 and 2.7 side by side
OK, so to do this you need sudo access
Download python and install it in /opt or ~/source. I put mine in ~/source
wget http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tgz
tar -xvzf Python-2.7.3.tgz
yum install gcc
cd Python-2.7.3
./configure
make altinstall
The command
make altinstall
is critical because it will prevent replacing the default python directory /usr/bin/python

8 comments:

  1. nice one.. i'm trying to do this very thing.. having troubles with it though.. cant seem to get the actual python.exe file to work :/
    thanks for posting this

    ReplyDelete
  2. i also get:
    make: *** No rule to make target `altinstall'. Stop.

    ReplyDelete
  3. Thanks a lot.
    Now to fire-fight with platform that needed a higher version!

    ReplyDelete
  4. Okay..
    I am stuck with two ptyhons but cannot get 2.7 to work with node.js

    I need to set python 2.4 (rpm installed) as primary (so that CentOS's yum and other things don't break)
    while I need python 2.7 for node.js

    I get the following error when I try to configure node.js (even for ./configure --help)
    --
    File "./configure", line 436
    fpu = 'vfpv3' if armv7 else 'vfpv2'
    ^
    SyntaxError: invalid syntax
    --

    Here's what I tried:
    1. alias
    before I run ./configure for node.js
    I did alias python=/usr/local/bin/python2.7
    Yet the configure script for node.js throws the above error.

    2. alternatives
    alternatives --install /usr/bin/python python /usr/bin/python2.4 1
    alternatives --install /usr/bin/python python /usr/local/bin/python2.7 2
    alternatives --config python
    here I set 2.7 as default.

    3. export PYTHON=/usr/local/bin/python2.7
    did expect this to work, and it didn't

    If you know how to use the two python versions simultaneously without breaking the other application's dependency, then kindly throw some light here.

    Your post was a good guide to have the two installation of python, especially for someone who will install the two from tarball.

    Need to know how to associate the two versions with respective apps.

    Thanks

    ReplyDelete
  5. Got an idea from here:
    https://github.com/joyent/node/wiki/Installation


    If that doesn't work, you can try creating symlinks to the old python in a directory which comes before python's in $PATH


    Here's what I did...

    python point to bin of 2.4
    so...
    #mv /usr/bin/python /usr/bin/python.old
    #ln -s /usr/local/bin/python2.7 /usr/bin/python
    #python -V
    shows 2.7

    now configure and install node.js
    after node.js is done, revert the changes done to python binary.

    ReplyDelete
  6. easy node install, thanks for blog entry saved my ass from a lot of work

    wget http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tgz
    tar xvf Python-2.7.3.tgz
    cd Python-2.7.3
    ./configure
    make altinstall
    cd /tmp/node-v0.8.5
    python2.7 configure
    make
    make install

    ReplyDelete