These lessons learned pertain to Python 2.6.1 on Redhat Enterprise Linux RHEL 4 / CentOS 4.

How to build Python 2.6.1 RPMs

# This is a required dependency
sudo yum install sqlite-devel
# This provides _tkinter.so which isn't listed as a depenency but is required nonetheless 
# (More info on this in this FAQ for 2.4 : http://www.python.org/download/releases/2.4/rpms/)
sudo yum install tcl-devel
cd /usr/src/redhat/SOURCES/
wget "http://www.python.org/ftp/python/2.6.1/Python-2.6.1.tar.bz2"
cd /usr/src/redhat/SPECS
bunzip2 -c /usr/src/redhat/SOURCES/Python-2.6.1.tar.bz2 | tar -vxO Python-2.6.1/Misc/RPM/python-2.6.spec > python-2.6.spec
# patch the spec file ( http://bugs.python.org/issue5063 )
wget "http://bugs.python.org/file12863/python-2.6.1.spec.diff"
patch python-2.6.spec python-2.6.1.spec.diff
# build
rpmbuild -bb --clean python-2.6.spec

How to install setuptools via RPM

I’m running RHEL 4 and the easiest way to install setuptools is to use the EPEL repositories existing RPM

http://download.fedora.redhat.com/pub/epel/4/i386/repoview/python-setuptools.html

Or rebuild the source RPM as follows :

# get setuptools http://pypi.python.org/pypi/setuptools#downloads
wget "http://pypi.python.org/packages/any/s/setuptools/setuptools-0.6c9-1.src.rpm#md5=82bac5d82a7e99bde9079b97f75bbe49"
sudo rpm -ivh /usr/src/redhat/RPMS/i386/python2.6-tools-2.6.1-1pydotorg.i386.rpm
sudo rpm -ivh /usr/src/redhat/RPMS/i386/python2.6-devel-2.6.1-1pydotorg.i386.rpm
# patch install.py 
# http://bugs.python.org/issue755286
wget "http://bugs.python.org/file5382/python-distutils-rpm-8.patch"
sudo mv python-distutils-rpm-8.patch /usr/lib/python2.6/distutils/command/install.py.issue755286.patch
sudo patch /usr/lib/python2.6/distutils/command/install.py /usr/lib/python2.6/distutils/command/install.py.issue755286.patch
# build
rpmbuild --rebuild setuptools-0.6c9-1.src.rpm