r/linuxquestions • u/mohamedibrahim456 • 1d ago
How can I package and install my Python application as a `.deb` package?
I have a project directory named `pkgmate`. I want to package the entire project so that installing a new version updates all of its files, including the application code and data files. I also want to be able to launch the application from the terminal using either `pkgmate` or `builder`.
The project is currently organized like this:
```text
pkgmate/
├── assets/
├── core/
├── data/
│ ├── builder.py (execuatble)
│ ├── builder_core.py
│ ├── graphics.json
│ ├── multimedia.json
│ ├── programming.json
│ └── sys/
├── package_managers/
├── tests/
├── ui/
├── pkgmate.py(execuatble)
└── README.md```
What is the recommended way to structure the `.deb` package so that all required project files are installed and updated together? How should I define the command-line entry points so that both `pkgmate` and `builder` work after installation?
And how to update the package next time i want to update?
I tried to search about that but i actually have no idea what to search plus ai ain't much help
2
u/dasisteinanderer 1d ago
firs thing you should do is re-structure you program to be a python package https://packaging.python.org/en/latest/tutorials/packaging-projects/
you probably want a pyproject.toml file at the project root, which should contain "[project.scripts]" which are generated by your python build system and serve as binaries (actually, python scripts) that jump into specified points in your python package.
then, you need to create the "debian" directory within the project, and fill it with the respective data, see https://wiki.debian.org/action/show/Python/LibraryStyleGuide?action=show&redirect=Python%2FPackaging
this is all a bit fiddly, but you can look at what other packages have done
1
u/Successful-Cookie644 1d ago
Hi. You can look up at my project
https://github.com/EugeneJk/Linux-Mint-power-mode-auto-changer
Look makefile to see how to build deb.
I used ChatGPT for quick search what I needed to do for making .deb
I hope it what you need.
1
u/scraping_solutions 1d ago
Since this is plain Python with nothing to compile, the simplest route is to skip debhelper and build the package tree by hand. Make a staging directory, copy the whole project into usr/lib/pkgmate/ inside it (data files included), and put two small executable shell scripts in usr/bin/ named pkgmate and builder. Each one just does exec python3 /usr/lib/pkgmate/pkgmate.py "$@" (and the same for the builder.py path under data/), so both commands work from the terminal.
Then add a DEBIAN/control file with Package, Version, Architecture: all, Maintainer, Depends: python3 and Description, and run dpkg-deb --build on the staging directory. To update, bump the Version field, rebuild, and install the new .deb with sudo apt install ./file.deb. Same package name with a higher version replaces the old files, and files you dropped from the new version get removed too.