Skip to content

Categories:

Building python2.6 for Debian Lenny

Though I am a fan of Debian and use it whenever I can in server environments it is sometimes frustrating that packages in Debian’s stable release are sometimes a tidbit outdated.

Though this generally isn’t a problem over at Inter-Actief we desperately need Python 2.6 on Debian Lenny, mainly due to the so much more excellent (and actually working) support for SSL.

After reading one hell of a lot of posts, blogs, looking around on the Debian Python project site and mail archives I concluded it would just be best and faster than actually waiting for packages by the Debian team to rebuild the python2.6 source-packages in experimental against de Debian Lenny base-system.

First and foremost I wish to express my gratitude and give credits to one of my fellow system admins at Inter-Actief and good friend Matthijs Kooijman for without his knowledge, patience and guidance it would have been one big hell for me to achieve this.

Now, let us begin…

Before we begin: this is just a guide on how one could achieve this. It might inadvertently break or cause problems on your system, though unlikely since Python 2.6 can run perfectly fine alongside 2.5. However, you have been warned, proceed at your own risk.

It all begins with creating a virtual machine with a total vanilla Debian Lenny install with the same architecture as the machine you want to install the packages on we are going to build, in my case, amd64 or as uname -m tells us, x86_64.

You can of course run these procedures directly on the target machine but since it brings quite a bunch of extra packages with it I decided to do it inside a VM to keep the target/production machine as clean as possible.

On top of that I installed openssh-server so I could log in to the VM remotely because having no clipboard support in VMWare was driving me insane.

Now, since we want to build python2.6 against the Lenny basesystem we’ll need a few things, such as gcc, python’s build-dependencies etc. We can of course issue the command apt-get build-dep python2.5 but that gave me more than I wanted and it missed a few things which are needed to build python2.6 so I installed the necessary packages manually.

apt-get install debhelper autoconf libreadline5-dev libncursesw5-dev tk8.4-dev libdb4.5-dev zlib1g-dev  blt-dev libssl-dev libbz2-dev libbluetooth-dev locales libsqlite3-dev libffi-dev mime-support libgpm2 netbase lsb-release bzip2 sharutils python-sphinx

Now thos were just the build-dependencies for Python 2.6, we also need a few tools to compile everything and build the packages:
apt-get install build-essential devscripts

Let that command run and complete, now we have everything we need to build Python 2.6 ourselves. As stated above we are going to use the Python 2.6 source packages from Experimental and build those ourselves, this ensures our packages adhere to standard Debian behaviour.

First, add the following to /etc/apt/sources.list:

deb-src http://ftp.nl.debian.org/debian/ experimental main non-free contrib

Or another mirror of your choice but make sure it has the Experimental sources, not all mirrors do.

Now run apt-get update to fetch the new package lists.

Time to get kinky!

cd /root
mkdir python26
cd python26
apt-get source python2.6
cd python2.6-2.6.4~rc1

Now, let us edit the control file so we can actually build this thing:  vim debian/control

What we need to do here is change the Mainter and the Build-Depends parameters.

  • Change Maintainer: Matthias Klose to your name and address
  • Change tk8.5-dev to tk8.4-dev
  • Change libdb4.7-dev to libdb4.5-dev

Good, that’s it when it comes to stuff we need to change. Now, prepare for a very long compile session.

dpkg-buildpackage -us -uc -b

This, once completed, finished, done testing etc. will have create a few Debian packages (.deb) and a change-file (.changes) in the parent directory.

cd ..
ls

idle-python2.6_2.6.4~rc1-1_all.deb
libpython2.6_2.6.4~rc1-1_amd64.deb
python2.6_2.6.4~rc1-1_amd64.deb
python2.6-dbg_2.6.4~rc1-1_amd64.deb
python2.6-dev_2.6.4~rc1-1_amd64.deb
python2.6-doc_2.6.4~rc1-1_all.deb
python2.6-examples_2.6.4~rc1-1_all.deb
python2.6-minimal_2.6.4~rc1-1_amd64.deb
python2.6_2.6.4~rc1-1_amd64.changes

Congratulations, you’ve just created your very own very personal Debian Lenny compatible Python 2.6 packages.

You can now install these packages, either manually using dpkg -i python2.6-minimal_2.6.4~rc1-1_amd64.deb and so on or create your own repository, add those .deb-files to it and then add your repository to apt’s sources and just issue the install command apt-get install python2.6

If you don’t know how but want to setup your own repository, see this article: http://www.debian-administration.org/articles/286

One thing, if you import those .deb’s into your repository with reprepro by feeding it the .changes-file you’ll need to edit that file and set the Distribution: part accordingly, this should be either lenny or stable.

One last thing I’d advise you to do, edit the following file: /usr/share/python/debian_defaults and add python2.6 to the supported part, but do not set it to default as it might break stuff in Lenny itself.

The reason for doing this? All the python-* packages will need to be recompiled too, such as python-pysqlite2 which will automatically be build against all supported versions the build system is aware of and without adding Python 2.6 to the debian_defaults file you’ll be building packages for just Python 2.4 and Python 2.5 which is just plain useless.

As you might be able to see, the python-* packages do not include a python version in the package name. This is because when building the package from source it will be compiled against all versions of python known to that system and then packaged into a single .deb-file.

One problem with this is that when you put it in a repository and then use apt-get update && apt-get upgrade the package is no different from the one from Debian’s own mirrors which will get precedence.

To fix that, we’ll bump the version of the package a bit.

So, here we go again:

cd /root
mkdir python-extra
cd python-extra
apt-get source python-pysqlite2
cd python-pysqlite2-2.4.1
dch --bin-nmu Local rebuild against python2.6

Now, python-pysqlite2 has a few additional build-dependencies which we will have to install first:
apt-get install python-all-dbg python-all-dev

You can just as well run:
apt-get build-dep python-pysqlite2

That will make sure all the build-dependencies for python-pysqlite2 are satisfied which actually is a better option than manually doing it as I did before.

If you added our earlier created 2.6 packages to a repository then also issue:
apt-get install python2.6-dbg python2.6-dev

If not, make sure you install the python2.6-dev en -dbg .deb-files we created earlier.

Though in this case it is not strictly necessary to edit the debian/control-file it might be wise to do so and change once again the Maintainer: line.

Now, just as with building Python 2.6 we need to issue the following command:
dpkg-buildpackage -uc -us -b

This command will complete in quite the short time, especially compared to compiling the whole of Python 2.6.

cd ..
ls

python-pysqlite2_2.4.1-1+b1_amd64.deb
python-pysqlite2-dbg_2.4.1-1+b1_amd64.deb
python-pysqlite2_2.4.1-1+b1_amd64.changes

As you can see, our package has the +b1 attached to its packagename now which basically means to apt that our version is newer than the one provided by the Debian mirrors themselves and our package will be installed instead if added to a repository and installed through apt.

NOTE: If the Debian team should release a new version of the python-* package you will need to run this procedure again as their package will have a higher version number and override yours in an upgrade.

Now either install the package with dpkg -i python-pysqlite2_2.4.1-1+b1_amd64.deb or edit the .changes-file as we did for the Python 2.6 package and add it to your repository, update apt and install as usual.

Need another python-* module? The same principle applies for all of them.

Don’t forget to satisfy the build-dependencies of each package you want to build first, can save you quite the trouble and weird error messages. Just search for the package on http://packages.debian.org and then navigate to the source package or just issue apt-get build-dep python-packagename to have apt take care of everything for you.

Good luck and have fun!

Posted in Projects, random.

Tagged with , , , , .


12 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. doug.shawhan says

    Thanks! Worked pretty well for me for the most part. Still can’t figure out why httplib2 won’t build. Did httplib2 build for you?

  2. Mark says

    this did not work for me. when i executed dpkg-buildpackage, i got the following message after a long time of compiling: “dpkg-buildpackage: failure: debian/rules build gave error exit status 2″. it failed several unit tests as well.

  3. Daenney says

    To be honest I do not know what can have triggered that error. Since I’m sourcing an experimental package here it might very well be that in the mean time a newer version was uploaded by a member of the debian python team that introduced a few problems inside the debian/rules file.

    It’s just a stab in the dark here but that seems most likely to me since it breaks on the rules file.

  4. Daenney says

    We do not use httplib2 so I have not tried to compile it yet. I can give it a go somewhere next week.

  5. Mark Van den Borre says

    Obvious typo:

    “dpkg-buikdpackage -us -uc -b” should be “dpkg-buildpackage -us -uc -b”

  6. Daenney says

    D’oh, thanks for that one…

  7. tomtom says

    Hmmm. Did not work for me.
    I have a Lenny System with

    ii python 2.5.2-3 An interactive high-level object-oriented language (default ve
    ii python-minimal 2.5.2-3 A minimal subset of the Python language (default version)
    ii python2.5 2.5.2-15 An interactive high-level object-oriented language (version 2.
    ii python2.5-minimal 2.5.2-15 A minimal subset of the Python language (version 2.5)
    ii python2.6 2.6.4-1 An interactive high-level object-oriented language (version 2.
    ii python2.6-minimal 2.6.4-1 A minimal subset of the Python language (version 2.6)

    But when I try to install a package I get the following error:

    dpkg: dependency problems prevent configuration of custompkg:
    custompkg depends on python (>= 2.6); however:
    Version of python on system is 2.5.2-3.

    Any help appreciated.

  8. Tony Maher says

    python2.6 has moved from experimental to testing so need ot modify the /etc/apt/source.list line accordingly.

  9. Brian says

    Python2.6 is now in unstable and not in experimental any more.

  10. Brian says

    Hence, the information in /etc/apt/sources.list should be the following.

    deb-src http://ftp.nl.debian.org/debian/ unstable main non-free contrib

  11. Brian says

    I got this error. Any idea?

    Traceback (most recent call last):
    File “/usr/lib/python2.5/site-packages/sphinx/__init__.py”, line 126, in main
    confoverrides, status, sys.stderr, freshenv)
    File “/usr/lib/python2.5/site-packages/sphinx/application.py”, line 83, in __init__
    self.setup_extension(extension)
    File “/usr/lib/python2.5/site-packages/sphinx/application.py”, line 122, in setup_extension
    raise ExtensionError(‘Could not import extension %s’ % extension, err)
    ExtensionError: Could not import extension pyspecific (exception: No module named writers.html)

  12. Brian says

    Got it to build, but it won’t install. Any tips?

    xen2:~# dpkg -i ./python2.6-minimal_2.6.5-1_amd64.deb
    Selecting previously deselected package python2.6-minimal.
    (Reading database … 84813 files and directories currently installed.)
    Unpacking python2.6-minimal (from …/python2.6-minimal_2.6.5-1_amd64.deb) …
    Setting up python2.6-minimal (2.6.5-1) …
    Linking and byte-compiling packages for runtime python2.6…
    pycentral: pycentral rtinstall: installed runtime python2.6 not found
    pycentral rtinstall: installed runtime python2.6 not found
    dpkg: error processing python2.6-minimal (–install):
    subprocess post-installation script returned error exit status 1
    Processing triggers for man-db …
    Errors were encountered while processing:
    python2.6-minimal



Some HTML is OK

or, reply to this post via trackback.