Python 2.7 on Ubuntu Python 2.7 on Ubuntu python python

Python 2.7 on Ubuntu


I did it with pythonbrew on my Ubuntu 10.10 machine.

$ python -VPython 2.6.6$ curl -kL https://raw.github.com/utahta/pythonbrew/master/pythonbrew-install | bash$ . $HOME/.pythonbrew/etc/bashrc$ pythonbrew install 2.7.1$ pythonbrew switch 2.7.1Switched to Python-2.7.1$ python -VPython 2.7.1

I also used it to install Python 3.2.


I recently backported Python 2.7 to Debian squeeze. Since Ubuntu 10.10 is newer than Debian squeeze, if you can do it on squeeze, you can certainly do it on Ubuntu. I don't have access to a Ubuntu 10.10 system. If I set one up, I'll test on it, and update this answer. So, here instead is a brief sketch of what I did on Debian.

First, a general and obvious comment, but something that is easily overlooked. One should not take the listed build dependencies of a Debian package too seriously. They may be far more specific than needed. For example, software like Python, which is designed to be portable and run over a wide array of systems, is unlikely to build depend on very specific versions of software. The runtime dependencies can be adjusted as well, but this should be done with more caution. However, runtime dependencies are mostly generated dynamically based on software that is already on this system, so usually that is not a big issue.

apt-cache policy python2.7python2.7:  Installed: 2.7.2-8  Candidate: 2.7.2-8  Version table:     2.7.2-12 0         50 http://debian.csail.mit.edu/debian/ unstable/main i386 Packages     2.7.2-8 0         50 http://debian.csail.mit.edu/debian/ testing/main i386 Packages *** 2.7.2-8 0        100 /var/lib/dpkg/status

Selecting the testing version we get

apt-get source python2.7=2.7.2-8

Looking at debian/control, we see the following build dependency lines.

Build-Depends: debhelper (>= 5), quilt, autoconf, libreadline-dev, libtinfo-dev, libncursesw5-dev (>= 5.3), tk8.5-dev, zlib1g-dev, blt-dev (>= 2.4z), libssl-dev, libexpat1-dev, sharutils, libbz2-dev, libbluetooth-dev [linux-any], locales [!armel !avr32 !hppa !ia64 !mipsel], libsqlite3-dev, libffi-dev (>= 3.0.5), mime-support, libgpm2 [linux-any], netbase, lsb-release, bzip2, libdb4.8-dev, gdb, python, help2manBuild-Depends-Indep: python-sphinxBuild-Conflicts: tcl8.3-dev, tk8.3-dev, tcl8.4-dev, tk8.4-dev, python2.7-xml, python-xml, autoconf2.13, libncurses5-dev

Most of this is easily satisfied on squeeze. With the handy utility apt-show-versions we get on my machine

apt-show-versions debhelper quilt autoconf libreadline-dev libtinfo-dev libncursesw5-dev tk8.5-dev zlib1g-dev blt-dev \libssl-dev libexpat1-dev sharutils libbz2-dev libbluetooth-dev locales libsqlite3-dev \libffi-dev mime-support libgpm2 netbase lsb-release bzip2 libdb4.8-dev gdb python help2man python-sphinxautoconf/squeeze uptodate 2.67-2blt-dev/squeeze uptodate 2.4z-4.2bzip2/squeeze uptodate 1.0.5-6debhelper/squeeze-backports uptodate 8.9.13~bpo60+1gdb/squeeze uptodate 7.0.1-2+b1help2man/squeeze uptodate 1.38.2libbluetooth-dev/squeeze uptodate 4.66-3libbz2-dev/squeeze uptodate 1.0.5-6libdb4.8-dev/squeeze uptodate 4.8.30-2libexpat1-dev/squeeze uptodate 2.0.1-7libffi-dev/squeeze uptodate 3.0.9-3libgpm2/squeeze uptodate 1.20.4-3.3libncursesw5-dev/squeeze uptodate 5.7+20100313-5libreadline-dev/squeeze uptodate 6.1-3libsqlite3-dev/squeeze uptodate 3.7.3-1libssl-dev/squeeze uptodate 0.9.8o-4squeeze5libtinfo-dev not installedlocales/squeeze uptodate 2.11.2-10lsb-release/squeeze uptodate 3.2-23.2squeeze1mime-support/squeeze uptodate 3.48-1netbase/squeeze uptodate 4.45python/squeeze uptodate 2.6.6-3+squeeze6python-sphinx/squeeze-backports uptodate 1.0.8+dfsg-2~bpo60+1quilt/squeeze uptodate 0.48-7sharutils/squeeze uptodate 1:4.9-1tk8.5-dev/squeeze uptodate 8.5.8-1zlib1g-dev/squeeze uptodate 1:1.2.3.4.dfsg-3

We see that everything except libtinfo-dev is available in squeeze. I do have the squeeze backport versions of debhelper and python-sphinx, but both of these are also available for debian squeeze in versions satisfying the build requirements.

Observe also that I have libncurses5-dev installed

apt-show-versions libncurses5-devlibncurses5-dev/squeeze uptodate 5.7+20100313-5

Both of these packages correspond to the source package curses 5.7+20100313-5. Observe that libtinfo-dev in fact replaces libncurses5-dev.

apt-cache show libtinfo-devPackage: libtinfo-devSource: ncursesVersion: 5.9-4Installed-Size: 279Maintainer: Craig Small <csmall@debian.org>Architecture: i386Replaces: libncurses5-dev (<< 5.9-3)Depends: libtinfo5 (= 5.9-4)

One would not expect python 2.7 to develop on such a specific version of curses, and in fact it doesn't. However, if you try to build the packages without satisfying the dependency you get

debuild -uc -usdpkg-checkbuilddeps: Unmet build dependencies: libtinfo-devdpkg-checkbuilddeps: Build conflicts: libncurses5-devdebuild: fatal error at line 1289:You do not appear to have all build dependencies properly met.You can use mk-build-deps to generate a dummy package whichDepends on all the required packages, or you can install themmanually using dpkg or apt using the error messages just abovethis message.

So, it is necessary to edit debian/control. Note that you also need to similarly edit the file debian/control.in, otherwise the controlfile will be incorrectly regenerated from control.in. The simplest thing to do is just remove libncurses5-devfrom the Build-Conflicts line and libtinfo-dev from the Build-Depends line, and then run debuild -uc -usagain. If you are going to have this package installed alongside the standard default Python 2.6 packages on Debian squeeze, youalso need to remove the two lines

Conflicts: python-profiler (<= 2.7.1-2)Replaces: python-profiler (<= 2.7.1-2)

Those lines are there because 2.7 includes the python-profiler functionality.If 2.7 is the default python, then python-profiler is no longer necessary. However, if one is installing 2.7 as a non-default Python, that reasoning does notapply, and python-profiler is still needed by 2.6.

This should build successfully, and result in the following list of binary packages.

ls -lah *.deb-rw-r--r-- 1 faheem staff 289K Jan 12 02:33 idle-python2.7_2.7.2-8_all.deb-rw-r--r-- 1 faheem staff 1.1M Jan 12 02:34 libpython2.7_2.7.2-8_i386.deb-rw-r--r-- 1 faheem staff 2.5M Jan 12 02:34 python2.7_2.7.2-8_i386.deb-rw-r--r-- 1 faheem staff  12M Jan 12 02:34 python2.7-dbg_2.7.2-8_i386.deb-rw-r--r-- 1 faheem staff 4.9M Jan 12 02:34 python2.7-dev_2.7.2-8_i386.deb-rw-r--r-- 1 faheem staff 6.0M Jan 12 02:33 python2.7-doc_2.7.2-8_all.deb-rw-r--r-- 1 faheem staff 692K Jan 12 02:33 python2.7-examples_2.7.2-8_all.deb-rw-r--r-- 1 faheem staff 1.7M Jan 12 02:34 python2.7-minimal_2.7.2-8_i386.deb

Finally, one can install the binary packages with

dpkg -i python2.7-minimal_2.7.2-8_i386.deb python2.7_2.7.2-8_i386.deb python2.7-dev_2.7.2-8_i386.deb libpython2.7_2.7.2-8_i386.deb 

Sometimes dpkg can be a little difficult about satisfying dependencies when they are all installed at once, so you might have to run apt-get -f install afterwards if you get dependency errors, or alternatively install the packages in smaller groups.


Well if the only thing you need is argparse (saw that in one of your comments!) you could just do :

pip install argparse

This is not exactly an answer to the exact question :-) , but indeed if you are only missing a few feature, many 2.7 features actually come from independent projects and/or some compatibility packages can be found, eg:

The list of 2.7 novelties is admittedly longer, but most of the other new features are probably not a big miss, and in exchange you do not mess around with multiple python installations on your box. Otherwise go with pythonbrew :-)