Simple python packaging for Debian / Ubuntu
Contents
(As requested by Jean-Fred)
One of the ‘pain points’ with working on deploying python stuff at Wikimedia is that pip
and virtualenvs
are banned on production, for some (what I now understand as) good reasons (the solid Signing / Security issues with PYPI, and the slightly less solid but nonetheless valid ‘If we use pip for python and gem for ruby and npm for node, EXPLOSION OF PACKAGE MANAGERS and makes things harder to manage’). I was whining about how hard debian packaging was for quite a while without checking how easy/hard it was to package python specifically, and when I finally did, it turned out to be quite not that hard.
Use python-stdeb.
Really, that is it. Ignore most other things (until you run into issues that require them :P). It can translate most python packages that are packaged for PyPI into .debs that mostly pass lintian checks. Simplest way to package, that I’ve been following for a while is:
- Install
python-stdeb
(from pip or apt). Usually requires the packagespython-all
,fakeroot
andbuild-essential
, although for some reason these aren’t required by the debian package forstdeb
. Make sure you’re on the same distro you are building the package for. git clone
the package from its source- Run
python setup.py --command-packages=stdeb.command bdist_deb
(orpython3
if you want to make Python 3 package) - Run
lintian
on it. If it spots errors, go back and fix them, usually by editing thesetup.py
file (or sometimes astdeb.cfg
file). This is usually rather obvious and easy enough to fix. - Run
dpkg -i <package>
to try to install the package. This will error out if it can’t find the packages that your package depends on. This means that they haven’t been packaged for debian yet. You can mostly fix this by finding that package, and making a deb for it, and installing it as well (recursively making debs for packages as you need them). While this sounds onerous, the fact is that most python packages already exist as deb packages and youstdeb
will just work for them. You might have to do this more if you’re packaging for an older distro (cough coughprecise
cough cough), but is much easier on newer distros. - Put your package in a repository! If you want to use this on Wikimedia Labs, you should use Labsdebrepo. Other environments will have similar ways to make the package available via
apt-get
. Avoid the temptation to justdpkg -i
it on machines manually :)
That’s pretty much it! Much simpler than I originally expected, and not much confusing / conflicting docs. The docs for stdeb
are pretty nice and complete, so do read these!
Will update the post as I learn more.
Author yuvipanda
LastMod 2014-08-19