Dealing with Python and Debian packages


Create a Debian package it’s not always a piece of cake. You need to think about where you are going to deploy installed files, what dependencies your application will need, what systems will be supported and so forth. If you are programming in Python and you want to distribute your application as a Debian package, you may have to deal with some additional problems:

  • If your application is supported by almost any Python version, you would like to make your package work with all of them, not only with the current one.
  • If your application requires a certain Python version, you will want your application to use that version, no matter if there are more versions installed on the system or if it is not the default one.

There are several approaches to solve those problems related with Python, and I am going to write about one of them (using Python-support) and the way I have used it on DeTraS. Of course, if you want to get detailed information or to know more details, I suggest you to read its guide (you may find it on /usr/share/doc/python-support/README.gz if you have installed python-support package) or you can find it on the web. All credit of this post goes to Python-support team🙂

Python-support allows to handle bite-compilation of Python modules when there are several Python versions installed on the system. If your Python application supports the most common versions of Python and you use this tool when you create your Debian package, you will almost forget of which Python version is running the user or is the default on his system. If your modules require a certain version of Python, you may use this tool to force the compilation of those modules in a certain Python version, so it will help you to deal with some problems.

DeTraS only has some private modules (they are not intended to be shared with any other module or application), so I will talk about how you can use Python-support with private modules. In first place, you will need to run dh_make, as I explain on this post. Then you should edit your debian/control file, adding building dependencies on python-support, python and debhelper on source package definition. You need to add dependencies on ${python:Depends} on binary package definition. You can see added dependencies on DeTraS control file on lines 6 and 14:

Source: detras
Section: x11
Priority: optional
Maintainer: Edmundo Álvarez Jiménez
Build-Depends: debhelper (>= 7), libdbus-glib-1-dev, libglib2.0-dev, xorg-dev, libpanel-applet2-dev
Build-Depends-Indep: python-support (>=0.8), python (>=2.6)
Standards-Version: 3.8.1

Package: detras
Architecture: i386 amd64
Depends: ${shlibs:Depends}, ${misc:Depends}, ${python:Depends}, python-soappy
Description: tools to track development activities on a X Window session
 DeTraS provides several tools to track development activities by registering
 applications that developers use on a X Window session. It also allows you
 to send collected data to a server and takes care about your privacy.
 This package provides you the DeTraS client, including:
    * TempusFugit to track data.
    * Squealer to upload your data.
    * Gnome applet to configure and monitor DeTraS.

The next step is to edit debian/rules file. Open your file and look for binary-indep target if your package is architecture independent, or binary-arch if it is architecture dependent. Insert the line dh_pysupport just before dh_installdeb and save your file. It’s mandatory to start the line with a tab character. If your program does not depend on a specific Python version and your modules are stored in a default directory (like /usr/share/$package or /usr/lib/$package), you are done. It’s time to build your package🙂

If you need some special Python version, you can add -V2.X option to dh_pysupport to pre-compile modules in Python 2.X version (of course, you have to change X with the desired version). In the case you are not going to install your modules in a default directory, you just need to pass the directory where you will deploy your module to dh_pysupport. Python-support will look for Python files there and will compile them on installation.

Finally, you may want to check if Python-support has detected your modules. To do that, once you have built your package with dpkg-buildpackage, you can check the file debian/$package/usr/shared/python-support/$package.private. This file should contain a list of Python modules detected and the Python version to compile them, if you had indicated one.

Happy hacking!

No Responses Yet to “Dealing with Python and Debian packages”

  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: