r/linux4noobs • u/mohamedibrahim456 • 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
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 intousr/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.pathso 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/GiggleSamurai 2d ago
Without the full Debian tooling, the simplest way is a folder like
pkgroot/holding the whole project inpkgroot/opt/pkgmate/, apkgroot/DEBIAN/controlfile (Package, Version, Architecture: all, Maintainer, Depends: python3, Description), and symlinkspkgroot/usr/bin/pkgmate -> /opt/pkgmate/pkgmate.pyandpkgroot/usr/bin/builder -> /opt/pkgmate/data/builder.py(both scripts need a#!/usr/bin/env python3first line and the executable bit), then rundpkg-deb --build --root-owner-group pkgroot pkgmate_1.0_all.deb. To update, bump Version in the control file, rebuild, andsudo apt install ./pkgmate_1.1_all.debreplaces the files the old version installed (and removes ones the new version no longer has).