January 04, 2014

Python package to deb-package

So, you want to create a debian package from your Python package. Okay, let's go.

-1
First of all, make sure you have written a 'setup.py' script for your Python package. It must be valid enough to be used with PyPI.
0
Now get prepared to actual action by installing some tools:

sudo apt-get install devscripts python-all-dev python-stdeb build-essential

1
Go to your package sources directory and run:

python setup.py --command-packages=stdeb.command sdist_dsc

2
Go to `deb_dist/PACKAGE_NAME/debian` and:
  1. add 'copyright' file: provide description of your license. Do not include it's full text into the file, write some reference to '/usr/share/common-licenses/YOUR_LICENSE' instead;
  2. check 'control' file: dependencies, description, long description, etc;
  3. check 'changelog' file: pay attention: follow a very strict format. It may be useful to store changelog permanently inside your package directory.

If something is wrong with formats or whatever, lintian will tell you during package check.

3
Build package:

cd deb_dist/PACKAGE_NAME
dpkg-buildpackage -rfakeroot -uc -us

4
Check, if everything is OK:

cd ..
lintian python-PACKAGE_NAME_VERSION_ARCH.deb

Make sure no errors (E) show their heads. There may be some warnings (W). Look through lintian tags and check their 'severity' and 'certainty' attributes. Your warnings may be not significant, such as 'new-package-should-close-itp-bug'.

5
Now you can install your package:

sudo dpkg -i python-PACKAGE_NAME_VERSION_ARCH.deb

You may also sign your package with your PGP key and put it to some PPA.

Good luck!