Packaging a python app for Ubuntu using dh-virtualenv

For a while I've been trying to find the best way to package a python app as a debian file that I can distribute for installing on Ubuntu.
I also didn't necessarily want to rely on the python packages that are distributed with the system because with python you tend to get used to having the latest packages installed through pip.
Then I found dh-virtualenv which is a very neat way of packaging python into debs with the key advantage that these apps are packaged as a virtualenv so that the latest packages can be included without relying on the packages on the system... But system packages can also be used.
In this post I've created an that example illustrates how to package a python script as a .deb using dh-virtualenv. The example can be found on github.


               sudo apt-get install python-dev git

  • Create a virtualenv (so that the latest pip and setuptools can be install and activate)

              virtualenv virt-example   
source ~/virt-example/bin/activate

Build the example debian package of the GUI

Download the example

             git clone   
cd python-debian-packaging-example
In the folder containing the source run
                         dpkg-buildpackage -us -uc -b
This should build a debian outside the folder that can be installed


The newly created debian package can be installed as you would any other package
[Obviously this is just an illustrative example so make sure that the installed files don't overwrite any existing applications. But I wouldn't expect anything to be called eximview or eximview2]

Explanations of the packaging files

This script is used to copy the .desktop entry, the icon and a bask script to run the app into the appropriate system folders.

This is the script that is copied to usr/bin and basically runs the app in the virtualenv that has been created by the deb install.


Note that this example doesn't take advantage of the main use of dh-virtualenv, which is packaging the latest dependencies with the app. But this can be done trivially by adding them to the requirements.txt file as explained in the dh-virtualenv documentation. ::...
当前网页内容, 由 大妈 ZoomQuiet 使用工具: ScrapBook :: Firefox Extension 人工从互联网中收集并分享;
若有不妥, 欢迎评注提醒:


订阅 substack 体验古早写作:

点击注册~> 获得 100$ 体验券: DigitalOcean Referral Badge

关注公众号, 持续获得相关各种嗯哼:


关于 ~ DebugUself with DAMA ;-)
公安备案号: 44049002000656 ...::