The Python package py2deb converts Python source distributions to Debian binary packages (the ones used for installation). It uses pip-accel (based on pip) to download, unpack and compile Python packages. Because of this py2deb is compatible with the command line interface of the pip install
command. For example you can specify packages to convert as command line arguments but you can also use requirement files if you want.
During the conversion process dependencies are automatically taken into account and converted as well so you don't actually have to use requirement files including transitive dependencies. In fact you might prefer not explicitly listing your transitive dependencies in requirement files because py2deb will translate the version constraints of Python packages into Debian package relationships.
The py2deb package is currently tested on CPython 2.7, 3.5, 3.6, 3.7 and PyPy 2 and 3. Unfortunately Python 3.8+ is not yet supported (see below). For usage instructions please refer to the documentation hosted on Read The Docs.
The py2deb package is available on PyPI, so installation is very simple:
$ pip install py2deb
There are some system dependencies which you have to install as well:
$ sudo apt-get install dpkg-dev fakeroot
Optionally you can also install Lintian (which is not a hard dependency but more of a "nice to have"):
$ sudo apt-get install lintian
When Lintian is installed it will be run automatically to sanity check converted packages. This slows down the conversion process somewhat but can be very useful, especially when working on py2deb itself. Currently py2deb doesn't fail when Lintian reports errors, this is due to the unorthodox ways in which py2deb can be used. This may change in the future as py2deb becomes more mature.
There are two ways to use the py2deb package: As the command line program py2deb
and as a Python API. For details about the Python API please refer to the API documentation hosted on Read the Docs. The command line interface is described below.
Usage: py2deb [OPTIONS] ...
Convert Python packages to Debian packages according to the given command line options (see below). The command line arguments are the same as accepted by the "pip install" command because py2deb invokes pip during the conversion process. This means you can name the package(s) to convert on the command line but you can also use "requirement files" if you prefer.
If you want to pass command line options to pip (e.g. because you want to use a custom index URL or a requirements file) then you will need to tell py2deb where the options for py2deb stop and the options for pip begin. In such cases you can use the following syntax:
$ py2deb -r /tmp -- -r requirements.txt
So the "--" marker separates the py2deb options from the pip options.
Supported options:
The following sections list possible improvements to the project:
The py2deb project builds on top of pip-accel, which was developed between 2013 and 2015 on top of pip >= 7.0, < 7.2
. Since that time pip has grown enormously: At the time of writing (in August 2020) we're now at pip 20!
None of the improvements made between pip 7-20 are available in pip-accel and py2deb and this has become somewhat of a glaring issue that plenty of users have run into (see #17, #18, #27 and #31).
Known issues being caused by this include:
- The old pip version prevents Python 3.8+ compatibility.
- The old pip version doesn't know about
python_requires
metadata provided by PyPI and this forces users to maintain constraints files themselves, even though this shouldn't be necessary. - While pip-accel supports installation from wheels, it was never exposed via the Python API and so py2deb lacks support for converting wheels (it currently needs source distributions).
The current state of affairs is best summarized in this comment. I'm hoping to complete the upgrade to newer pip and pip-accel releases in the coming weeks (as of this writing in August 2020) but can't commit to a date.
Find a way to facilitate (explicit / opt-in) installation of system wide files (not related to Python per se) based on a Python distribution? This could significantly reduce the need for "wrapper packages" that basically just pull in packages converted by py2deb and drop a few configuration files into place.
- Related issues
See issue #7 for a related discussion.
Investigate the feasability of supporting conversion of binary wheels. Slowly but surely the Python community seems to be gravitating towards (binary) wheels and once gravity has shifted we don't want to be left in the dust! 😉
Dive into PEP-440 and see if it can be fully supported? Then this question on Reddit can finally get a satisfying answer 🙂.
There are several projects out there that share similarities with py2deb, for example I know of stdeb, dh-virtualenv and fpm. The documentation includes a fairly detailed comparison with each of these projects.
The latest version of py2deb is available on PyPI and GitHub. The documentation is hosted on Read the Docs and includes a changelog. For questions, bug reports, suggestions, etc. please create an issue on GitHub.
This software is licensed under the MIT license.
© 2020 Peter Odding, Arjan Verwer and Paylogic International.