a lot of the following information will be obvious to people with a good 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 would like to present a solution which, so far, hasn't disturbed the operating system and allows one to run ipython (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 neither python nor linux anyhow).
disclaimer: my knowledge of linux is very limited. i write the following with the intent of helping out newbies such as myself. please do not hold me reponsible if you follow my procedure and end up with a system that's pushing up the daisies.
note: all of the above and below is valid for the gnome desktop environment. i haven't tried it with kde and, now that it's finally working, i don't think i will.
- install a fresh copy of ubuntu 8.10 if your system has been hopelessly pulverized by trials, errors and packages scattered in the wrong places.
- before doing anything directly related to python, you need to install the following packages. the easiest way is to open a terminal session and type sudo aptitude install package-name, for each and every package below. this 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
- download and extract the python 2.6.1 source. from inside the source directory, enter ./configure --prefix=/home/yourusername/python. ignore, of course, the period that precedes this sentence. this will setup python to install into a 'python' directory inside your home directory, far away from anything system-like.
- type make. at the output's end, 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.
- type sudo make install. i tried to do a sudo 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.
- now, if you type python you should get the default ubuntu python version (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'd want.
- optional: if you need an additional python module (such as numpy), install it from its source directory by typing sudo /home/yourusername/python/bin/python setup.py install --prefix=/home/yourusername/python. this runs the setup script with the 2.6.1 interpreter and install the module into the 2.6.1 directory (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/bin/python /usr/local/bin/python2.6. 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 make you feel a tad better. (note: i keep entering all commands with the 'sudo' prefix because for some reason the python installer didn't grant me permissions to write to its directory structure. i suppose you could use chmod and modify the permissions but i'm not familiar with either the syntax or the results and i'm not going to learn it now.)
- install setuptools: download the egg file for python 2.6 and enter sh setuptools-0.6c9-py2.6.egg. this is why the symbolic link above has to 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. do not download anything. with setuptools installed, you can simply go into your python bin directory (cd /home/yourusername/python/bin) and type ./easy_install IPython. download and install will be automatic.
- edit the .bashrc file in your home directory so as to add the path to ipython to your environment. simply add PATH=$PATH:/home/yourusername/python/bin to the end of the file. i 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 'run' command executes the proper interpreter: enter sudo gedit /usr/share/geany/filetypes.python and modify the run_cmd line to read: run_cmd=python2.6 "%f" (this will make use of the symbolic link you created earlier).
- you can now run ipython, develop in a gui ide, and still install packages through aptitude or synaptic without all hell breaking loose. enjoy.


