I was asked today to install Python 2.7 on a CentOS based node and I thought I’d take this oportunity to add a companion article to my Python 2.6 article.
We’re all well aware that CentOS is pretty backwards when it comes to having the latest and greatest sotware packages and is particularly finicky when it comes to Python since so much of RHEL depends on it.
As a rule, I refuse to rush in and install anything in production that isn’t in a manageable package format such as RPM. I need to be able to predictably reproduce software installs across a large number of nodes.
The following steps will not clobber your default Python 2.4 install and will keep both CentOS and your developers happy.
So, here we go.
Install the dependancies.
sudo yum -y install rpmdevtools tk-devel tcl-devel expat-devel db4-devel \
gdbm-devel sqlite-devel bzip2-devel openssl-devel \
ncurses-devel readline-devel
Setup you RPM build envirnoment.
rpmdev-setuptree
Grab my spec file.
wget https://raw.github.com/nmilford/specfiles/master/python-2.7/python27-2.7.2.spec \
-O ~/rpmbuild/SPECS/python27-2.7.2.spec
wget http://www.python.org/ftp/python/2.7.2/Python-2.7.2.tar.bz2 \
-O ~/rpmbuild/SOURCES/Python-2.7.2.tar.bz2
Build RPM. (FYI, the QA_RPATHS variable tells the rpmbuild to skip some file path errors).
QA_RPATHS=$[ 0x0001|0x0010 ] rpmbuild -bb ~/rpmbuild/SPECS/python-2.7.2.spec
Install the RPMs.
sudo rpm -Uvh ~/rpmbuild/RPMS/x86_64/python27*.rpm
Now on to the the setuptools.
Grab my spec file.
wget https://raw.github.com/nmilford/specfiles/master/python-2.7/python27-setuptools-0.6c11.spec \
-O ~/rpmbuild/SPECS/python27-setuptools-0.6c11.spec
Grab the source.
wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz \
-O ~/rpmbuild/SOURCES/setuptools-0.6c11.tar.gz
Build the RPMs.
rpmbuild -bb ~/rpmbuild/SPECS/python27-setuptools-0.6c11.spec
Install the RPMs.
sudo rpm -Uvh ~/rpmbuild/RPMS/noarch/python27-setuptools-0.6c11-milford.noarch.rpm
Now, we’ll install MySQL-python as an example.
Grab the mysql-dev package
yum -y install mysql-devel
Grab, build and install the MySQL-python package.
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
python2.7 setup.py build
python2.7 setup.py install
Like with the previous Python 2.6 article, note how I called the script explicitly using the following python binary: /usr/bin/python2.7
Now we’re good to give it the old test thus:
python2.7 -c "import MySQLdb"
If it doesn’t puke out some error message, you’re all set.
Happy pythoning.