r/linux4noobs • • 2d ago

How can I package and install my Python application as a `.deb` package?

/r/linuxquestions/comments/1ybpy8u/how_can_i_package_and_install_my_python/
1 Upvotes

3 comments sorted by

1

u/aeveris 2d ago

This seems to be a fairly simple guide to follow: https://www.geeksforgeeks.org/python/build-a-debian-packagedeb-from-your-python-program/

Then there are some official tutorials and docs:

I unfortunately can't give any directly actionable advice since so far I've mainly built packages for Arch, but the geeksforgeeks article is probably a good starting point.

In the end package files generally contain a directory structure that mirrors where the files of your package should be once the package is installed. So your binaries will go into a usr/bin/ directory inside the package, libraries into usr/lib/... and so on.

If your executable scripts rely on other python files in your package, you might need to add the path you put those in to sys.path so that your executable scripts can find them.

Updating your package should be relatively easy: you update the version number and create a new package file from your updated sources and then install it.

1

u/Cherry_Sparkm2 2d ago

man, that guide makes it look like packing a .deb is just a matter of *not* breaking your own stuff first

1

u/GiggleSamurai 2d ago

Without the full Debian tooling, the simplest way is a folder like pkgroot/ holding the whole project in pkgroot/opt/pkgmate/, a pkgroot/DEBIAN/control file (Package, Version, Architecture: all, Maintainer, Depends: python3, Description), and symlinks pkgroot/usr/bin/pkgmate -> /opt/pkgmate/pkgmate.py and pkgroot/usr/bin/builder -> /opt/pkgmate/data/builder.py (both scripts need a #!/usr/bin/env python3 first line and the executable bit), then run dpkg-deb --build --root-owner-group pkgroot pkgmate_1.0_all.deb. To update, bump Version in the control file, rebuild, and sudo apt install ./pkgmate_1.1_all.deb replaces the files the old version installed (and removes ones the new version no longer has).