How to easily package python softwares for ubuntu

May 24, 2010  

This post will show you how to quickly package any python software for debian or ubuntu.

The magic comes from stdeb

The first step is to install it:

$ sudo apt-get install python-stdeb

stdeb can download, package and install any python software hosted on PyPi using the pypi-install command. It works almost like easy_install or pip.

$ pypi-install Werkzeug

You can check that the package is installed:

$ dpkg -l | grep werkzeug
ii  python-werkzeug    0.6.2-1    The Swiss Army knife of Python web developme

If you want more control on the buildprocess and access the debian source package, you must follow theses steps: First you must find and download the archive of the software you want to package:

# http://pypi.python.org/pypi/Jinja2/2.4.1
$ wget http://pypi.python.org/packages/source/J/Jinja2/Jinja2-2.4.1.tar.gz

Now we will create the debian source package with py2dsc

$ py2dsc Jinja2-2.4.1.tar.gz

The source package is in the deb_dist folder. If you want to build the binary package with debuild:

$ cd deb_dist/jinja2-2.4.1/
$ debuild

You now have python-jinja2_2.4.1-1_all.deb in deb_dist! Happy packaging ;)