0

I recently upgraded to Debian Bookworm from Bullseye.

I am aware that installation of python packages requires a different method as compared to pip install <package>. Therefore, I install new python packages using pipx which works well.

Question: The packages that have already been installed using pip don't work as they were working before. For example, I had installed pdfCropMargins using pip and have used it extensively before upgrading to Bookworm.

After the upgrade, I get the following error:

pdf-crop-margins -a 5 pgfmanual.pdf Traceback (most recent call last): File "/home/vrgovinda/.local/bin/pdf-crop-margins", line 5, in <module> from pdfCropMargins.pdfCropMargins import main ModuleNotFoundError: No module named 'pdfCropMargins' 

As per my understanding, I guess that pipx is now managing the python packages and is expecting the modules in some other location.

Am I right? If yes, how to resolve this issue?

If No, What is the reason for this error and how to resolve this issue?

Thanks in advance.

2 Answers 2

2

It is recommended against using pip to install a library at the system level because it won't be integrated with apt. It means that (1) the version of the library installed via pip may be incompatible with other system libraries, and (2) when you upgrade your system that library won't be automatically upgraded.

pipx only solves (1): it creates a virtual environment that is separated from the system and install your lib/tool inside.

pipx doesn't solve (2): when the virtual environment was created for (1), it had to link with an existing python, surely it linked against the python of your system at /usr/bin/python3.9, but that binary got removed when you upgraded your system to bookworm.

I am not aware of a tool that can upgrade a virtual environment from one python version to another. I am afraid you'll have to list all tools you installed via pipx, uninstall and reinstall them. The new virtual environment will use the new system python at /usr/bin/python3.11.

I would recommend against "freezing" python to a specific version, e.g. by manually compiling/installing another one under an alternative path. And to use pipx with that frozen python. That frozen python won't receive any automatic security update.

Try to stick to apt :/

1

Python's version compatibility is lousy, even between minor update releases of the language - e.g. if you use pip to install a library module while running python 3.10 then it won't be available when you upgrade to python 3.11. You'll need to install it again for the new version of python.

To make the version compatibility problem even worse, python devs & community fetishise this is as a "feature" rather than a bug and have developed a baroquely complicated virtual environment paradigm to work around it - but that's not surprising, since python devs & users tend to view the OS their program is running on as a problem to be avoided/worked-around rather than a useful thing they can benefit from.

7
  • So, I have to re-install all existing python packages? Commented Aug 24, 2023 at 1:30
  • only the ones you installed with pip/pipx. distro packages of python libraries should be fine. Commented Aug 24, 2023 at 1:31
  • Oh! That's too much! I have one whisper package that pulls in few hundred MBs of dependencies. Commented Aug 24, 2023 at 1:33
  • Either reinstall them all or use "the python way", which is to have lots of different versions of python installed and use, e.g. venv, to separate them from each other so that they can all have their own isolated library dirs. Alternatively, package each of the required libraries for debian in a local repo and then make a whisper package that depends upon them....this is more work but is ultimately the better solution. Another alternative is to bundle everything required into a chroot or a snap or flatpak image, or a docker image or some other container. Commented Aug 24, 2023 at 1:39
  • Can I manually shift some files [created by pip] into separate directories inside the venv so that pipx thinks that those packages have been installed with pipx? Commented Aug 26, 2023 at 12:04

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.