New method for installing Python 2.6.4 (with mysql-python) on CentOS 5.5

So I wrote in an earlier post about alt-installing Python 2.6 from source on CentOS, which was easy enough.  But, this made it more difficult to maintain and deploy as well as add modules.  So, I was lucky enough to come across a nice little yum repository hosted by Rizwan Kassim (Geekymedia.com) that contained an RPM that would do the alt-install work for me :)

I’m aware that EPEL has a Python 2.6 package, but the Geekymedia RPMs have a whole flurry of modules you can add as well as an RPM for setuptools which will make your life immeasurably easier when running Python 2.4 and 2.6 side-by-side for installing python packages.

The only problems with the Geekymedia RPMs are that the binary packages are all 32-bit (I’m running servers here folks!) and I was unable to get the MySQL-python26 one to work right for me.

So, let’s get down to business.

First I wanted to get rid of the existing python26 alt-install and EPEL rpms I installed.  This is only needed if you followed my last tutorial.

rpm -qa | grep python26 | rpm -e --nodeps $(xargs)
rm -rf /usr/local/lib/python2.6
rm -rf /usr/local/include/python2.6
rm -rf /usr/local/lib/libpython2.6.a
rm -rf /usr/bin/python2.6
rm -rf /usr/include/python2.6
rm -rf /usr/lib/python2.6
rm -rf /usr/lib64/libpython2.6.so.1.0
rm -rf /usr/lib64/python2.6
rm -rf /usr/local/bin/python2.6
rm -rf /usr/local/bin/python2.6-config
rm -rf /etc/rpm/macros.python26
rm -rf /root/MySQL-python26-1.2.3-0.3.c1.src.rpm
rm -rf /usr/bin/python26
rm -rf /usr/share/doc/python26-2.6.5
rm -rf /usr/share/doc/python26-libs-2.6.5
rm -rf /usr/src/Python-2.6.4/PC/os2emx/python26.def

Now, let us get started in earnest.  The next few steps are for compiling and building our own distributable RPMs and only need to be done once, after this you can use the already built RPMs everywhere.

Install stuff for building the RPMs:

yum -y install rpm-build gcc-c++

Install the dependancies for building the RPMs from source.

yum -y install readline-devel openssl-devel gmp-devel ncurses-devel \ 
gdbm-devel expat-devel libGL-devel libX11-devel tcl-devel tk-devel \ 
tix-devel sqlite-devel db4-devel

Grab the Geekymedia src rpms.

rpm -Uvh http://mirrors.geekymedia.com/centos/python26-2.6-geekymedia1.src.rpm
rpm -Uvh http://mirrors.geekymedia.com/centos/python26-setuptools-0.6c9-5.src.rpm

Build and install the alt-installed Python 2.6 RPMs

rpmbuild -bb /usr/src/redhat/SPECS/python.spec
rpm -Uvh /usr/src/redhat/RPMS/x86_64/python26-2.6-geekymedia1.x86_64.rpm
rpm -Uvh /usr/src/redhat/RPMS/x86_64/python26-libs-2.6-geekymedia1.x86_64.rpm
rpm -Uvh /usr/src/redhat/RPMS/x86_64/python26-tools-2.6-geekymedia1.x86_64.rpm
rpm -Uvh /usr/src/redhat/RPMS/x86_64/python26-devel-2.6-geekymedia1.x86_64.rpm
rpm -Uvh /usr/src/redhat/RPMS/x86_64/python26-test-2.6-geekymedia1.x86_64.rpm
rpm -Uvh /usr/src/redhat/RPMS/x86_64/tkinter26-2.6-geekymedia1.x86_64.rpm

Build and install the alt-installed setuptools:

rpmbuild -bb /usr/src/redhat/SPECS/python26-setuptools.spec
rpm -Uvh /usr/src/redhat/RPMS/noarch/python26-setuptools-0.6c9-5.noarch.rpm  

For future machines you can dump all those RPMs in your own repo or on an nfs share and install them.  You’ll only need to do something like:

yum -y install tk tix
rpm -Uvh /path/to/rpms/python26/*.rpm

And finally, we can install the PyPI MySQL-python package (you may need to login and out again to refresh your PYTHONPATH):

yum -y mysql-devel
curl http://superb-sea2.dl.sourceforge.net/project/mysql-python/mysql-python/1.2.3/MySQL-python-1.2.3.tar.gz | tar zxv
cd MySQL-python-1.2.3
python26 setup.py build
python26 setup.py install

Note how I called the script explicitly using the following python binary: /usr/bin/python26

Now we’re good to give it the old test thus:

python26 -c "import MySQLdb"

If it doesn’t spit out an error, you’re aces. Bazinga!

Share
  • Pingback: Tweets that mention New method for installing Python 2.6.4 (with mysql-python) on CentOS 5.5 | blog.milford.io -- Topsy.com

  • Captain

    Hi Nathan,

    Very instructive tutorial, unfortunately I get stuck at item…
    rpmbuild -bb /usr/src/redhat/SPECS/python.spec

    ========================================================
    [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

    • Chingon27

      do what subrat said. use rpm -Uvh /usr/src/redhat/RPMS/x86_64/*.rpm instead of the 6 rpm-Uvh commands.

      Nathan, thanks for the write up. It helped TONS.

      • uzrbin

        Thanks for the article, it looks very promising. However I’m getting the same failed dependency error as Captian here. I tried running the command as subrat said however I only get

        Preparing… ########################################### [100%]
        package e1000-7.6.15a-1.x86_64 is already installed
        package bnx2-1.7.6b-1.x86_64 is already installed

        and when i go to rpmbuild the setuptools I get

        error: Failed build dependencies:
        python26-devel is needed by python26-setuptools-0.6c9-5.noarch

        I’m more used to working with Ubuntu (apt-get) on my machine, so I’m a little new to yum/rpms. Setting up our servers running CentOS has been interesting. Thanks.

    • Chingon27

      do what subrat said. use rpm -Uvh /usr/src/redhat/RPMS/x86_64/*.rpm instead of the 6 rpm-Uvh commands.

      Nathan, thanks for the write up. It helped TONS.

  • Subrat

    On the “Build and install the alt-installed Python 2.6 RPMs” section, it is better to do:

    rpmbuild -bb /usr/src/redhat/SPECS/python.spec
    rpm -Uvh /usr/src/redhat/RPMS/x86_64/*.rpm

    That way, there will not be any dependency issues.

    Great post though!
    Subrat

  • DJSnoopy

    Big big thx for this How-To
    I spend three nights here to get this working on my own.
    Your howto did it in 20 minutes…

    THANKS champ!

  • Chris

    Thank you so much!
    Your instruction is clear and it went on smoothly on my server.

  • Pingback: CentOS安装python2.6以及MySQL-python » 闻斯行诸?

  • Gratitude

    Thank  you so much, I tried to run this stuff for over a week.
    Also thanks to Subrat for his tip!

  • biskandar

    It failed after compile the source , please find the log console below :

    [root@cs2 ~]# rpmbuild -bb /usr/src/redhat/SPECS/python.spec(cut)
    Wrote: /usr/src/redhat/RPMS/x86_64/python26-2.6-geekymedia1.x86_64.rpm
    Wrote: /usr/src/redhat/RPMS/x86_64/python26-libs-2.6-geekymedia1.x86_64.rpm
    Wrote: /usr/src/redhat/RPMS/x86_64/python26-devel-2.6-geekymedia1.x86_64.rpm
    Wrote: /usr/src/redhat/RPMS/x86_64/python26-tools-2.6-geekymedia1.x86_64.rpm
    Wrote: /usr/src/redhat/RPMS/x86_64/tkinter26-2.6-geekymedia1.x86_64.rpm
    Wrote: /usr/src/redhat/RPMS/x86_64/python26-test-2.6-geekymedia1.x86_64.rpm
    Wrote: /usr/src/redhat/RPMS/x86_64/python26-debuginfo-2.6-geekymedia1.x86_64.rpm
    Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.19143
    + umask 022
    + cd /usr/src/redhat/BUILD
    + cd Python-2.6
    + rm -fr /var/tmp/python26-2.6-root
    + exit 0

    [root@cs2 ~]# 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

     

    • http://blog.milford.io Nathan Milford

      rpm -Uvh /usr/src/redhat/RPMS/x86_64/*.rpm will install all the RPMs together so you don’t have the dependency error.