|
2008-11-21
Tags: Programming Python 2.6.1 on UbuntuPython 2.6.1 is the new stable Python version, but Ubuntu 8.10 Intrepid Ibex does not come with it. Here is how to install it though. First of all, you must learn about Python 2.6. Excited about the new features? Then now realize that while Python 2.6 prepares you for 3.0, it also makes your code incompatible with 2.5 if you use any of the new features! You must keep this in mind when you decide what to use! Most library authors won't bother updating their code with Python 2.6 features, as this would mean incompatibility with Python 2.4 and 2.5 (as well as 3.0). Python 2.6 is a version that is only compatible with itself. In other words, there are two antagonic forces here: On the one hand, you want to use the latest features of the language and write modern code that won't have to be heavily rewritten/updated soon (and using Python 2.6 is the best option for that right now, because nobody is using Python 3.0 yet); on the other hand, the lack of libraries and batteries that you can use, as well as other people using your code, may dictate that you must stay in previous versions for a long time. We would be talking about using Python 3.0 here if only there were any libraries for it already... Latest Zope/Plone still use Python 2.4! In these times, simple libraries that are more likely to be ported sooner to 3.0 make a good choice. If you have to stay in Python 2.5... you still can import these: On the other hand, if you are targeting Python 2.6, why would you not use all its features? Therefore, add this to the top of your files: To sum up, Python 2.6 is for people who can get away with using Python 2.6. These will benefit from having fewer changes to make when the time to upgrade to 3.0 comes, and from using new language features right now. But there is a small price to pay in library installation complexity, as we shall see soon. (Keep reading.) Installing Python 2.6.1 on Ubuntu Intrepid IbexDownload the sources: Decompress them: Install dependencies: Configure, make, test: Now you can do one of two things. Either create a .deb package: checkinstall -D --pkgname=python2.6.1 --pkgversion=2.6.1 --maintainer=nandoflorestan@gmail.com--inspect --backup=yes --install=no make altinstall And make sure you answer YES when asked to create a default set of docs! ...or install directly: The final step of the installation is to make your new python and python2.6 binaries available in the path, such that they will be found before python2.5. However, you had better do this for your user only, lest your whole Ubuntu operating system suffer (since all Linux distros depend heavily on Python). Being cautious this way, I create symbolic links to python and python2.6 from the bin directory of my user: Now you can test the interpreter: This tutorial is based on these. Now let us install a couple libraries so that our new Python 2.6 may be minimally useful: Library hellNow if you decide to go ahead and use 2.6, you are in library hell -- at least when the library you need is not pure Python. For instance, to be able to manipulate images, you must install PIL yourself, and it may not be trivial: The last command fails in Ubuntu Intrepid Ibex, saying: "_imagingtk.c:20:16: error: tk.h: No such file or directory" If you run "locate tk.h", you discover the missing file is really at: /usr/include/tcl8.4/tk.h Because this is a gcc problem and I am just a Python guy, I don't know how to solve it. I wonder if I really need this _imagingtk stuff... I don't use TK... So I just uninstall the python-tk and tk packages. This way it succeeds and just says: An alternative solution to the above problem might be to just turn TKINTER support off by commenting out these lines in setup.py (starting at 328): So now I test PIL: Unfortunately one important test fails, showing a new problem for me to solve: Since all required libraries are installed, I don't know what is going on. Googling the problem, I see people have solved this by repeating the whole process after everything is in place. Yeah I know, this is stupid. Anyway, I go ahead and delete the whole directory and repeat the steps and this time it works: Library hell indeed. If it took one working day to install each library. Fortunately, pure Python libraries written for 2.5 seem to work just as well with 2.6: SetuptoolsInstalling setuptools is quite easy: After this, I find that I can run both bpython and ipython interactive interpreters, just reusing their old eggs that were already installed in my system for Python 2.5. I just change the shebang at the top of the commands to this: This way, our Python 2.6 can be picked automatically (depending on $PATH). cherrypy, genshi and most other packages just work too. Conclusion
|