Score:2

How to install apt dependencies from setup tools?

kr flag

I am trying to create deb package from python setup tools. To do that, I tried adding install_requires as in this link But it seems, this is for pip modules, not apt packages. How or where to set dependency packages for that in setup tools? Please help me on this.

My sample application

We can add python packages using setup tools to created deb file. We can add apt packages as dependencies using fpm. But both combined, not sure how to set.Even I tried using the setup tools deb file as source to fpm deb creation but didnt work

One more option I tried to just use a post install script to install python dependencies at the end. Can you please check this once, the post install is not working.

For testing, I created a basic command.

fpm -s empty -t deb -n test --after-install ./tmp/post-install.sh

post-install.sh content is very basic used for testing.

#!/bin/bash
echo "testing install"
mkdir -p /tmp/testing
pip install torc

once the deb file is created, tested that on an ubuntu 20 and 22 machine and got below error as post install script not found.

vagrant@vagrant:~$ sudo apt install -y /vagrant/test_1.0_all.deb
Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'test' instead of '/vagrant/test_1.0_all.deb'
The following NEW packages will be installed:
  test
0 upgraded, 1 newly installed, 0 to remove and 107 not upgraded.
Need to get 0 B/1,118 B of archives.
After this operation, 0 B of additional disk space will be used.
Get:1 /vagrant/test_1.0_all.deb test all 1.0 [1,118 B]
Selecting previously unselected package test.
(Reading database ... 41035 files and directories currently installed.)
Preparing to unpack /vagrant/test_1.0_all.deb ...
Unpacking test (1.0) ...
Setting up test (1.0) ...
dpkg (subprocess): unable to execute installed test package post-installation script (/var/lib/dpkg/info/test.postinst): No such file or directory
dpkg: error processing package test (--configure):
installed test package post-installation script subprocess returned error exit status 2
Errors were encountered while processing:
test
E: Sub-process /usr/bin/dpkg returned an error code (1)
Score:1
cn flag

Python packages such as on PyPI via pip, and apt repos such as the debs in Debian, are different systems. Python's packaging systems can only include Python code and bindings, notice they are installed to various site-packages directories under a Python path. (This type of separate system is a mild annoyance to me, even when I know there is not a portable way to unify all packages.)

Your setup.py dependency on net-tools among other things cannot be met. Python packaging has no knowledge of apt, or other OS distros' package mangers for that matter.

Remove from install_requires everything not on PyPI index. Leave only what can be installed with setuptools. There might not be any, a glance at what you have shows use of Python standard library.

Document the dependencies on non-Python packages, possibly with a standalone shell script or Makefile that installs them.

Consider creating deb packages wrapping this python application, consistent with Debian Python policy. Advantages include being able to put the dependencies in package metadata, so apt can install them for you automatically. It remains a setuptools installed Python application, but contained in a deb.

Several of them are not in use by your Python program now, 'git','tmux','screen','vim','emacs','htop','valgrind'. As someone unfamiliar with what you are doing, I'm wondering why a thing needs both tmux and screen. Separate mandatory requirements for this program, from your wish list of packages you install on systems. A package just to pull a grab bag of personal preferences ideally has no code, to decouple from programs that do things.

Calling programs to do system admin things reminds me of the existing automation scripting framework Ansible. ansible-core has very few Python dependencies, but calls a wide variety of external programs or third party libraries depending on what you are doing. By convention, code takes care to detect missing things at run time and tell the user. Not ideal to miss detecting deps until then, but from a Python package there is not an obvious way depend on a non-Python thing. Especially if this needs to work for diverse Linux, BSD, and Unix environments, as Ansible does.

kr flag
Thanks for the detailed description, I know that apt and python packages are different. We can add python packages using setup tools to created deb file. We can add apt packages as dependencies using fpm. But both combined, not sure how to set.Even I tried using the setup tools deb file as source to fpm deb creation but didnt work
John Mahowald avatar
cn flag
If you are going for a deb package, please edit your question to show the source of that. Discuss the dependencies you want. "Didnt work" is not a sufficient problem description.
kr flag
I added those files already by sharing the public repo url. I tried one more option today but that is giving a different error with post install, can you see the above details added and give any input on that
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.