Building python 2.6.4 RPM for CentOS 5.4

CentOS is an enterprise linux distribution. And as such, it doesn’t really like anything new, unless it is a security patch. So it mostly contains older packages that are proven to be stable and secure. Any security patches and changes are backported to the older packages. This is all right for majority of the tools, but some really needs upgrading. Python is a very good example. Python release, which is included in CentOS 5.4 is a rather old 2.4 branch. If you’re serious about python development, you really want to have 2.6. Unfortunately there is no CentOS RPM available. So here’s how to build your own.

First, you need to install RPM devtools:

# yum install rpmdevtools

Then setup your local RPM build tree:

$ rpmdev-setuptree

This will create RPM build tree (~/rpmbuild/) in your home directory. Just a reminder – never, ever, under any circumstances, build RPMs as root user. Just a reminder. Obviously, you knew that already, right?

You also want to get and install additional header files and libraries, such as TCL/TK, expat, sqlite, etc, that are used to build some Python components:

# yum install tk-devel tcl-devel expat-devel db4-devel gdbm-devel sqlite-devel

Now we’re ready to start building an RPM. Get the RPM spec file from source build tree and copy it to your rpmbuild/SPECS directory, also copy the tarball to your build directory:

$ wget http://www.python.org/ftp/python/2.6.4/Python-2.6.4.tar.bz2
$ tar jxf Python-2.6.4.tar.bz2
$ cp Python-2.6.4/Misc/RPM/python-2.6.spec ~/rpmbuild/SPECS/
$ cp Python-2.6.4.tar.bz2 ~/rpmbuild/SOURCES/

This spec file is slightly broken and if you try building an RPM with it, it most likely is going to fail. So you need to patch it. The proposed patch has been submitted to python bug tracking system in the days of 2.6.1 release, but hasn’t yet been implemented. This patch doesn’t seem to work with 2.6.4 release and needs changing as well.

I have modified original 2.6.1 patch file slightly so that it can be used to build 2.6.4 Python RPM. You download it and apply to the original .spec:

$ cd ~/rpmbuild/SPECS/
$ wget http://www.grenadepod.com/wp-content/uploads/python-2.6.4.spec.diff
$ patch python-2.6.spec python-2.6.4.spec.diff

You should be OK to build the RPM now, but it’ll most likely fail with minor rpath-check errors, such as:

ERROR   0001: file '/usr/lib/python2.6/lib-dynload/_bsddb.so' contains a standard rpath '/usr/lib' in [/usr/lib]
ERROR   0001: file '/usr/lib/python2.6/lib-dynload/_sqlite3.so' contains a standard rpath '/usr/lib' in [/usr/lib]

Which indicates that some components are using hardcoded library paths. It’s not a big issue and can be ignored. Run build command as this:

$ QA_RPATHS=$[ 0x0001|0x0010 ] rpmbuild -ba python-2.6.spec

It should now build without any issues and the result is a set of python RPMs:

$ QA_RPATHS=$[ 0x0001|0x0010 ] rpmbuild -ba python-2.6.spec
...
Wrote: /home/pulegium/rpmbuild/SRPMS/python2.6-2.6.4-1gpod.src.rpm
Wrote: /home/pulegium/rpmbuild/RPMS/i386/python2.6-2.6.4-1gpod.i386.rpm
Wrote: /home/pulegium/rpmbuild/RPMS/i386/python2.6-devel-2.6.4-1gpod.i386.rpm
Wrote: /home/pulegium/rpmbuild/RPMS/i386/python2.6-tkinter-2.6.4-1gpod.i386.rpm
Wrote: /home/pulegium/rpmbuild/RPMS/i386/python2.6-tools-2.6.4-1gpod.i386.rpm
Wrote: /home/pulegium/rpmbuild/RPMS/i386/python2.6-debuginfo-2.6.4-1gpod.i386.rpm
...
$

This is it… You now have python RPMs that you can install on your CentOS 5.x server.

I’m planning to create my little own repository, where I’ll put this (and other) packages. For now, you can download python 2.6.4 source RPM if you want to change something in the spec file and rebuild it yourself.

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • LinkedIn
  • Live
  • Netvibes
  • NewsVine
  • Reddit
  • Slashdot
  • StumbleUpon
  • Technorati
  • Twitter
  • Yahoo! Bookmarks

Related posts:

  1. Sorting out YUM repositories on CentOS 5.4
  2. Use SSH to upgrade WordPress plugins automatically
  3. Building and running Google Chrome OS on VirtualBox
  4. Using OpenID for authentication in Django