I wanted to 'upgrade' my python from 2.5 to 2.6 on Ubuntu. Unfortunately, I could not find .deb packages for Ubuntu. Fortunately, the Python 2.6 sources (sig) are available, so I can compile it from source. Here's what I had to do to get it running. (Short version: apt-get build-dep python2.5
and apply this patch to disable unavailable and outdated modules.)
I have Python 2.5 installed and wanted to keep it, as Ubuntu 8.04 is a long term support version and I did not want to break this support by changing to a maybe non-compatible Python version.
Python uses a configure-style installation procedure. First, extract the Python sources:
tar xzf Python-2.6.tgz
cd Python-2.6
I configured Python to stay out of my usual directories and install itself to /opt/python2.6
:
./configure --prefix=/opt/python2.6
make
I thought that's all, however I get an error message like this:
Failed to find the necessary bits to build these modules:
_hashlib _ssl bsddb185
bz2 gdbm readline
sunaudiodev
To find the necessary bits, look in setup.py in detect_modules() for the module's name.
The easiest way to fix is to install the build dependencies for Python 2.5, because they seem to be identical to the build dependencies of Python 2.6:
apt-get build-dep python2.5
make
However, there's still an error message:
Failed to find the necessary bits to build these modules:
bsddb185 sunaudiodev
To find the necessary bits, look in setup.py in detect_modules() for the module's name.
bsddb185
refers to the historic version 1.85 of Berkeley DB (now Oracle Berkeley DB), and sunaudiodev
is necessary for audio stuff on Sun. I'm wondering why Python tried to find 'the necessary bits to build these modules', as I don't run a 1.85 version of Berkeley DB, nor do I use Sun. Unfortunately, I could not find any documentation on how to switch off compiling these sources. I guess, this could be improved.
Anyways, hacking setup.py was the way to go. Of course, it is not as easy as adding bsddb185
and sunaudiodev
to the disabled_modules
list at the beginning of setup.py. So I hacked the (bogus) test for the modules in detect_modules
like the error message suggested, resulting in this patch.
patch -p1 < python2.6-disable-old-modules.patch
make
sudo make install
This installed python 2.6 into /opt/python2.6. Set up links to your bin directory, and you're done.
ln -s /opt/python2.6/bin/python2.6 ~/.root/bin/python-2.6
ln -s /opt/python2.6/bin/pydoc ~/.root/bin/pydoc-2.6
Usually, I use checkinstall, but this time everything is nicely packed into /opt/python2.6, which I can just delete, should I ever want to get rid of Python 2.6 (which I doubt).
Notes
The first time I ran, I got this message:
Failed to find the necessary bits to build these modules:
_hashlib _ssl bsddb185
bz2 gdbm readline
sunaudiodev
To find the necessary bits, look in setup.py in detect_modules() for the module's name.
I think I found Ubuntu packages for some of them:
- _hashlib and _ssl in libssl-dev
- bz2 in libbz2-dev
- gdbm in libgdbm-dev
- readline in libreadline5-dev