Recently I needed to test a Django app under Python 2.4. I’m using Ubuntu 10.10 and the lowest packaged version of Python in the repositories is 2.6. I decided to compile Python 2.4 myself and use it in a virtualenv environment to test the app. There were a couple of little gotchas that caught me when I was doing this, so I thought I’d write-up the process.
Step 1: Install the Build Dependencies
Python 2.6 is close enough to 2.4 that the dependencies haven’t changed much (if at all).
sudo apt-get build-dep python2.6
Step 2: Download Python 2.4 Final
wget http://www.python.org/ftp/python/2.4/Python-2.4.tgz
tar -zxvf Python-2.4.tgz
Step 3: Configure and Install Python 2.4
My first attempt at building Python 2.4 failed with a buffer overflow. I found a Japanese forum post that had solved the issue by setting BASECFLAGS=-U_FORTIFY_SOURCE during the configure stage.
./configure BASECFLAGS=-U_FORTIFY_SOURCE
make
sudo make install
Step 4: Fix the Default Python Version
The make install step sets Python 2.4 as the default version of Python. I wanted to keep that at 2.6. So…
sudo rm /usr/local/bin/python
sudo ln -s /usr/bin/python2.6 /usr/local/bin/python
Step 5: Install into Virtualenv
I wanted to set up a virtualenv environment to test the app. Here I specify which version of python I want to use for the interpreter and activate it.
virtualenv env -p python2.4 --no-site-packages
source env/bin/activate
