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).
DISCLAIMER: My knowledge of linux is superficial. I write the following with the intent of helping out newbies such as myself. Do not hold me reponsible if you follow my method and end up with a system that’s pushing up the daisies.
NOTE: This method has been tested on GNOME, the default desktop environment for my distribution. I haven’t tried it with KDE and, now that it’s finally working, I don’t think I will.
ACKNOWLEDGEMENT: I would never have gotten Python 2.6.1 and Ubuntu to work together if it hadn’t been for the precious help of wacky, a member of the Python forum, who saw me through several nightmarish reinstallations of both Ubuntu and Python. Several of his suggestions have been incorporated into the steps below.
I suggest you read through the entire list of steps so that you have an idea of what’s going to happen before actually running any command.
- Install a fresh copy of Ubuntu 8.10 if your system has been hopelessly pulverized by repeated tests, errors and packages scattered in the wrong places.
- Before doing anything directly related to Python, you need to install the packages listed below. The list is an amalgam of several suggestions I found around the web, so one package or more might not be absolutely essential. But since it works, here’s the list:
- build-essential
- libncursesw5-dev
- libreadline5-dev
- libssl-dev
- libgdbm-dev
- libbz2-dev
- libc6-dev
- libsqlite3-dev
- libdb-dev
- tk-dev
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-nameYou 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 - Download and extract the Python 2.6.1 source. From inside the source directory, enter (still and always, one single line):
./configure --prefix=/home/yourusername/python/2.6This will setup Python to install into a ‘python/2.6′ directory inside your home directory, far away from anything system-like. You may choose to simply name the directory ‘python’, but the ’2.6′ subdirectory will help separate the installation from yet another custom setup, such as version 3.0, if you ever need to install one. Note, though, that this doesn’t mean I’ve tested the steps described in this tutorial with Python 3.0. - Compile Python with the standard command:
makeWhen the compile process finishes, read the few last lines it printed: you might get a couple of modules which can’t be found. I don’t remember their names but from searching around I gather that a lot of people can’t seem to find them and that nobody really cares. Most importantly, make sure that you don’t get a module missing error for zlib or readline, which are essential for the following steps. The packages installed previously will have taken care of that, though. - Install Python. I tried to do a make altinstall (after going through the Python source readme file), but for some reason I ended up without an executable. So just go through a regular install. Since you’re installing the Python files into your home directory, you don’t need to use sudo:
make install - Now, if you enter python in the terminal you should get the default Python version that comes with Ubuntu (currently 2.5.2). Typing which python should point to /usr/bin/python, not to the directory you just installed 2.6.1 into. All of this is normal and is actually what you’re looking for.
- Optional: if you need an additional Python module (such as Numpy), install it from its source directory by typing:
/home/yourusername/python/2.6/bin/python setup.py install --prefix=/home/yourusername/python/2.6This runs the setup script using the 2.6.1 interpreter and installs the module into the 2.6.1 directory structure (since we’re using the same prefix we specified when installing Python itself). - Create a symbolic link to the 2.6.1 interpreter so that the next step doesn’t blow up in your face:
sudo ln -s /home/yourusername/python/2.6/bin/python /usr/local/bin/python2.6It is important that you do not use a different name of your fancy for the link. Now, if you enter python you’ll still have 2.5.2, whereas entering python2.6 will launch, well, 2.6.1. This will also make sure that non-system versions of Python have to be run explicitly. Keeping the ‘python’ command reserved for the exclusive use of the system’s Python version is likely to avoid headaches in the future. - In order to use the easy_install command which facilitates the installation of additional modules, you first need to install setuptools: download the egg file for Python 2.6 and enter:
sh setuptools-0.6c9-py2.6.eggThis is the reason why the symbolic link created in the previous step must be called ‘python2.6′ (the setuptools script runs a python2.6 exec command and will complain about a missing 2.6 version if it’s not linked with ‘python2.6′). - Optional but highly recommended: install IPython, an enhanced command-line environment for Python. Do not download anything manually. With setuptools installed, you can simply go into your Python bin directory (with cd /home/yourusername/python/2.6/bin) and type:
./easy_install IPythonApparently you may also enter the following directly, which saves you the directory switching part:easy_install-2.6 IPythonI haven’t tried it myself, though. Anyway, download and install will be automatic. - You have to add the path to IPython to your terminal environment, so that the executable can be launched from any directory. Add the following line to the end of the .bashrc file which is located in your home directory.
PATH=$PATH:/home/yourusername/python/2.6/binI suppose you could create a symbolic link instead but i haven’t tried it. - If you use Geany for Python development, you need to edit one of its configuration files so that the application’s Run command executes the proper interpreter:
sudo gedit /usr/share/geany/filetypes.pythonModify the run_cmd line to read:run_cmd=python2.6 "%f"This will use the symbolic link you created earlier.
You can now run IPython, develop in the Geany IDE, and still install packages through aptitude or the Synaptic Package Manager without all hell breaking loose. If you’re using a tiny screen and touchpad I strongly recommend installing GNOME Do to avoid mousing around too much. Enjoy.
12 Comments
Thanks!
I found this to be incredibly useful. I wanted to use Python 2.6 in conjuction with virtualenv, to set up a django development environment. I actually found that virtualenv makes the process a little easier, since it automatically installs setuptools into the virtal environment.
In case you are curious, when creating the virtual environment, use the -p option to specify the path to the desired python interpreter:
virtualenv -p /path/to/python2.6/python ENV_NAME
Again, thanks for the great how-to!
Thank you!
I had just gotten to this step and got the missing zlib message.
I knew that something else was wrong.
Thanks for writing this and saving me, I’m sure, a TON of time and frustration.
My pleasure. Saving tons of frustrations was the whole point of taking the time to write this…
There’s an Ubuntu package that will install all the dependencies in one shot:
apt-get install build-dep python2.5
(The python 2.6 dependencies are the same as for 2.5, so the available 2.5 Ubuntu package will suffice).
Thanks! Great job.
Should add that I did this for Python 2.6.2 in Ubuntu 8.04 and worked flawlessly.
There should be no need to add prefix to a command like:
/home/yourusername/python/2.6/bin/python setup.py install –prefix=/home/yourusername/python/2.6
that python already knows what its prefix is.
Thanks.
Excellent!!!
This was extremely helpful. Thank you
when i get to step 9 is gives me “sh: Can’t open setuptools-0.9c9-py2.6.egg” any ideas?
Iwant the setup of python ………..thanks
So helpful!
I’m running Ubuntu 11.10 on an EEE PC 1215b, so I also used the mods recommended at http://askubuntu.com/questions/21547/what-are-the-packages-libraries-i-should-install-before-compiling-python-from-so
And for total beginners like me, the file download and directory navigation from
http://www.saltycrane.com/blog/2008/10/installing-python-26-source-ubuntu-hardy/
was also helpful.
Thanks for offering the results of your exhaustive problem-solving!
One Trackback
[...] Per farlo vi consiglio vivamente di seguire le indicazioni riportate in quest’ottima guida: http://www.talino.org/tutorials/install-python-261-without-trashing-ubuntu/ [...]