Context
I want to use the debian package to install python3 and then python packages. Python3 is installed using apt and python pacakges with pip3 installed with apt.
Here is the folder tree :
service/
├── DEBIAN/
│ ├── control
│ ├── postinst
│ └── preinst
└── usr/
└── local/
└── lib/
└── systemd/
└── system/
└── file.py
DEBIAN/control :
Package: service
Version: 0.1
Architecture: all
Depends: python3-pip, python3-dev
Maintainer: me <me@me.com>
Description: service installation
DEBIAN/preinst
#!/bin/bash
sudo apt install pyton3-pip
sudo apt install python3-dev
sudo pip3 install mypackage1
sudo pip3 install mypackage
exit 0
DEBIAN/postinst
#!/bin/bash
echo "success"
exit 0
sudo dpkg --build service/
Problem
To test the installation i then do the following :
sudo dpkg -i service
The following error then appears :
(Reading database ... 25477 files and directories currently installed.)
Preparing to unpack service.dev
Citing for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 5489 (dpkg) .. 5s
Citing for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 5489 (dpkg) .. 0s"
Solution First, reboot.
So here the problem come from the apt is dpkg is the low-level packaging tool that apt uses to handle packages.
What does it means ?
When we use dpkg and then call apt, it calls itself, it's the reason it is waiting for the lock to remove, because it uses the same ressources.
The solution here is to remove from the scripts any call to apt.
Preinst then becomes :
DEBIAN/preinst
#!/bin/bash
sudo pip3 install mypackage1
sudo pip3 install mypackage
exit 0
How to install python3-pip then ?
We have to use 3 commands lines :
sudo dpkg -i service.deb
Here the new output :
(Reading database ... 25477 files and directories currently installed.)
Preparing to unpack service.dev
sudo pip3: command not found
sudo pip3: command not found
Unpacking service (0.1) ....
dpkg: dependency problems prevent configuration of service:
service depends on python3-pip; however
Package python3-pip is not installed.
service depends on python3-dev; however
Package python3-devis not installed.
dpkg: error processing package service (--install):
dependency problems - elaving unconfigured
Errors were encoutnered while processing
service
sudo apt -f install
Successfully installed
sudo dpkg -i service.deb
...
Successfully installed package1
...
Successfully installed package1
...
success
...