dh-virtualenv 0,0,4,0,1,0,3 travis-ci python

Python virtualenvs in Debian packages


Build Status Docs



dh-virtualenv is a tool that aims to combine Debian packaging with self-contained virtualenv based Python deployments.

The idea behind dh-virtualenv is to be able to combine the power of Debian packaging with the sandboxed nature of virtualenvs. In addition to this, using virtualenv enables installing requirements via Python Package Index instead of relying on the operating system provided Python packages. The only limiting factor is that you have to run the same Python interpreter as the operating system.

For complete online documentation including installation instructions, see the online documentation.

Using dh-virtualenv

Using dh-virtualenv is fairly straightforward. First, you need to define the requirements of your package in requirements.txt file, in the format defined by pip.

To build a package using dh-virtualenv, you need to add dh-virtualenv in to your build dependencies and write following debian/rules file:

          dh [email protected] --with python-virtualenv

Note that you might need to provide additional build dependencies too, if your requirements require them.

Also, you are able to define the root path for your source directory using --sourcedirectory or -D argument:

          dh [email protected] --with python-virtualenv --sourcedirectory=root/srv/application

NOTE: Be aware that the configuration in debian/rules expects tabs instead of spaces!

Once the package is built, you have a virtualenv contained in a Debian package and upon installation it gets placed, by default, under /opt/venvs/<packagename>.

For more information and usage documentation, check the accompanying documentation in the doc folder, also available at Read the Docs.

How does it work?

To do the packaging, dh-virtualenv extends debhelper’s sequence by inserting a new dh_virtualenv command, which effectively replaces the following commands in the original sequence:

  • dh_auto_clean
  • dh_auto_build
  • dh_auto_test
  • dh_auto_install
  • dh_python2
  • dh_pycentral
  • dh_pysupport

In the new sequence, dh_virtualenv is inserted right before dh_installinit.

Running tests

$ nosetests ./test/test_deployment.py

Building the documentation locally

If you execute the following commands in your clone of the repository, a virtualenv with all necessary tools is created. invoke docs then builds the documentation into doc/_build/.

command . .env --yes --develop
invoke docs

To start a watchdog that auto-rebuilds documentation and reloads the opened browser tab on any change, call invoke docs -w -b (stop the watchdog using the -k option).

Code of conduct

This project adheres to the Open Code of Conduct. By participating, you are expected to honor this code.


Copyright © 2013-2017 Spotify AB

dh-virtualenv is licensed under GPL v2 or later. Full license is available in the LICENSE file.

Related Repositories



Python virtualenvs in Debian packages ...



debhelper add-on for packaging software written in Python in a venv/virtualenv ...



Simple example of packaging a python app for debian using dh-virtualenv ...



A Python example project using dh-virtualenv to build. ...



Python virtualenvs in Debian packages ...

Top Contributors

nailor jhermann 1stvamp phillipod mjksmith kgk asottile GMLudo jvrsantacruz dstufft ionrock noplay thinkingpotato lamby hashar adamchainz dnephin einarf elonen Lykathia Jc2k mkohler mgwilliams moritz Pankrat akheron philipcristiano pfista schainker-digbil walrusVision


-   0.11 zip tar
-   0.10 zip tar
-   0.9 zip tar
-   0.8 zip tar
-   0.7 zip tar
-   0.6 zip tar
-   0.5 zip tar