stdeb
stdeb is a Python utility that extends distutils to simplify the creation of Debian source packages from Python packages. It provides new distutils commands (like `sdist_dsc`, `bdist_deb`) and command-line utilities (like `pypi-install`, `py2dsc`) to automate the conversion process. While it attempts to provide sensible defaults, many aspects of the resulting Debian package can be customized via a configuration file. The library maintains a regular release cadence, with version 0.11.0 released in September 2025, continuing active development and support for modern Python versions.
Warnings
- breaking stdeb has removed support for Python 2.x and now requires Python 3.7 or newer. Additionally, it requires a minimum `debhelper` version of 12 for building Debian packages.
- gotcha The `pypi-install` command-line utility provides a quick way to convert and install a PyPI package as a `.deb`, but it does not guarantee proper fulfillment of all Debian package dependencies and bypasses customization options. Manual intervention for dependencies is frequently required.
- gotcha Debian packages generated by `stdeb` (especially those with extension modules) are highly sensitive to the build environment. Installing a `.deb` on a different Debian/Ubuntu version than where it was compiled can lead to undefined behavior or breakages.
- breaking stdeb relies on extending `distutils` commands via `setup.py`. With Python 3.12+, `distutils` was removed from the standard library. While `setuptools` provides a compatibility shim, direct reliance on `distutils` might lead to future compatibility issues or require specific `setuptools` versions.
- gotcha When using the `debianize` command (or `bdist_deb`), `stdeb` generates a `debian/` directory. The `Build-Depends` in the resulting `debian/control` file often requires manual review and adjustment to correctly specify all necessary system-level and Python package build dependencies.
- gotcha System-level packages like `python3-all` (for Python 3 projects) and `dh-python` are often crucial runtime or build dependencies for `stdeb` to function correctly, but might not be explicitly pulled in by `pip install stdeb` alone. Missing these can lead to cryptic build failures.
Install
-
pip install stdeb
Imports
- stdeb.command
python setup.py --command-packages=stdeb.command <command>
- pypi-install
pypi-install mypackage
Quickstart
mkdir my_python_project
cd my_python_project
# Create a dummy setup.py
cat <<EOF > setup.py
from setuptools import setup, find_packages
setup(
name='my-sample-package',
version='0.1.0',
packages=find_packages(),
scripts=['my_script.py'],
description='A simple test package for stdeb.',
author='Example User',
author_email='user@example.com',
install_requires=[],
)
EOF
# Create a dummy script
mkdir my_sample_package
cat <<EOF > my_sample_package/__init__.py
EOF
cat <<EOF > my_sample_package/my_script.py
import sys
def main():
print("Hello from my_sample_package!")
print(f"Running with Python {sys.version_info.major}.{sys.version_info.minor}")
if __name__ == '__main__':
main()
EOF
# Generate a Debian binary package (.deb)
python3 setup.py --command-packages=stdeb.command bdist_deb
echo "\nGenerated .deb file(s) in:"
ls deb_dist/*.deb