Is there a standard way to create Debian packages for distributing Python programs? Is there a standard way to create Debian packages for distributing Python programs? python python

Is there a standard way to create Debian packages for distributing Python programs?


It looks like stdeb will do what you want.

Also, for installing scripts, I strongly recommend distribute's console_scripts entry point support.


The right way of building a deb package is using dpkg-buildpackage, but sometimes it is a little bit complicated. Instead you can use dpkg -b <folder>, and it will create your Debian package.

These are the basics for creating a Debian package with dpkg -b <folder> with any binary or with any kind of script that runs automatically without needing manual compilation (Python, Bash, Perl, and Ruby):

  1. Create the files and folders in order to recreate the following structure:

     ProgramName-Version/ ProgramName-Version/DEBIAN ProgramName-Version/DEBIAN/control ProgramName-Version/usr/ ProgramName-Version/usr/bin/ ProgramName-Version/usr/bin/your_script

    The scripts placed at /usr/bin/ are directly called from the terminal, note that I didn't add an extension to the script. Also you can notice that the structure of the deb package will be the structure of the program once it's installed. So if you follow this logic if your program has a single file, you can directly place it under ProgramName-Version/usr/bin/your_script, but if you have multiple files, you should place them under ProgramName-Version/usr/share/ProgramName/all your files and place only one file under /usr/bin/ that will call your scripts from /usr/share/ProgramName/

  2. Change all the folder permission to root:

     chown root:root -R /path/to/ProgramName-Version
  3. Change the script's permissions:

     chmod 0755 /path/to/the/script
  4. Finally, you can run: dpkg -b /path/to/the/ProgramName-Version and your deb package will be created! (You can also add the post/pre inst scripts and everything you want, it works like a normal Debian package)


Here is an example of the control file. You only need to copy-paste it in to an empty file called "control" and put it in the DEBIAN folder.

Package: ProgramNameVersion: VERSIONArchitecture: allMaintainer: YOUR NAME <EMAIL>Depends: python2.7, etc , etc,Installed-Size: in_kbHomepage: http://example.comDescription: Here you can put a one line description. This is the short Description. Here you put the long description, indented by one space.

The full article about Debian packages can be read here.


This article by Barry Warsaw helped me in getting quite far through the process. I still had to do a lot of searching on the side, though, and I read most of the Ubuntu packaging guide some time in the past.

Having a good setup.py is a really good advice. I found these two guides quite good: