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.
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:
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:
- 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.