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).
Thanks! It worked on my laptop!
Thank you, it works brilliantly.
Work for me too! Thanks
Or just skip it!
http://www.saltycrane.com/blog/2008/10/installing-python-26-source-ubuntu-hardy/
Thanks, this helped a lot for me trying to install 2.6 on Intrepid. I had to add sudo apt-get install tk8.5 tk8.5dev
so if _tkinter module still fails to build, there's your problem.
> sudo apt-get install tk8.5 tk8.5dev Reading package lists... Done Building dependency tree Reading state information... Done E: Couldn't find package tk8.5dev
Any ideas?
There is a minus between tk8.5 and dev:
sudo apt-get install tk8.5 tk8.5-dev
There's actually no need to apply your patch to setup.py. Python complains about not being able to build those modules, but it will still build and install just fine without them.
If you want to avoid building from source, you can get a .deb package off of launchpad. Instructions here
After your patch it worked like a charm!
Thank YOU
oh man! great! thanks a lot!
Hi! I've installed python 2.6 succesfully following this post, thank you so much. But python 2.6 don't recognize other "modules" of python, like pygame - wich I need. I tried to make a symbolic link to the pygame installed(works in python 2.5), creating the link /opt/python2.6/include/python2.6/pygame linking to /usr/include/python2.5/pygame. But it didn't work. How do I make it work?
The python 'modules' are stored in
/usr/lib/python2.5/site-packages(not.../include). Python uses a search path to find the module you want toimport.There are many ways to fix your problem, depending on what you need:
--- For a single script, just link to
/usr/lib/python2.5/site-packages/pygamein the directory where you start your script.--- Or, for a single script, adjust the module search path before importing pygame (which, by the way, will give you access to all Python2.5 modules):
--- For every python2.6 script, link to the python2.5 module:
Of course, you could also install pygame and direct it to your new python2.6.
Thanks
Wow, it works! Thanks!!!
The above instructions worked well. However, I still had a couple of modules that could not be built - namely "dl" and "imageop". This was cleared up by the README in that "imageop" soes not work on 64 bit platforms and "dl" dynamic loading does not work via dlopen(). disabled both from building and finished with the make install. I also tried the launchpad instructions but the platform I was building on was hardy and not intrepid.
After several trials and tribulations, I finally managed to get an independent Python 2.6.1 version running smoothly on Ubuntu 8.10 (“Intrepid”), without interfering with the system’s reliance on Python 2.5 and without breaking the entire package dependency system. The procedure described here has been successfully carried out on the Easy Peasy distribution of Ubuntu (ex-”Ubuntu-eee”), specifically tailored for the Asus EEE-PC. It should work, though, with any other 8.10 version of Ubuntu. It has also been tested successfully on Ubuntu 8.04 (“Hardy”).
A lot of the following information will be obvious to people with a thorough knowledge of both Linux and Python. However, coming from Mac OSX, things haven’t been that obvious. For the poor souls who will be frantically googling for “zlib”, “zipimport.ZipImportError”, “setuptools”, “ipython”, “readline” and “ubuntu”, I offer a series of steps which, so far, haven’t disturbed the operating system and allow one to run the essential IPython environment (and a lot more) without pulling one’s hair out. It’s actually quick and easy and involves no hacking whatsoever (I wouldn’t know how to hack either Python or Linux anyhow).
The easiest way to install a package is to use the aptitude command. Make sure you’re connected to the internet, open a terminal session and type the following: sudo aptitude install package-name You will be prompted for your password the first time you invoke the sudo command, which executes everything typed after it as a “superuser” (or “root” user). Instead of entering the command for each and every package, you can may prefer to enter them all at once (all of the following should be typed on a single line): sudo aptitude install build-essential libncursesw5-dev libreadline5-dev libssl-dev libgdbm-dev libbz2-dev libc6-dev libsqlite3-dev libdb-dev tk-dev
Andreas,
I want to use your patch in a python 2.6.4 builder for debian project I have. (http://bitbucket.org/chris.mahan/debian-stable-python-2.6.4-deployer/) rather than linking from your blog.
Is that ok? What's your preferred license if any?
Let me know. Thanks.
Chris Mahan chris.mahan@gmail.com
Chris,
The above mentioned patch is in the public domain.
Excellent! Thank you.