Debain stable wants me to install Python modules using pipx. So I do
$ pipx install auditwheel
$ pipx ensurepath
$ python3 -m pipx ensurepath
$ python3
Python 3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import auditwheel
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'auditwheel'
>>>
What am I doing wrong?
2
Answers
From Python 3.11 onward, Debian encourages the users to create a separate Python virtual environment to install Python packages.
Because Debian declares its Python install to be externally-managed,
pip
(and other installers) will refuse to install packages system-wide. Installation is only possible in virtual environments or separate Python installs.This is because Python package installers (like
pip
) are unaware of the constraints that APT-managed packages have on libraries and versions. See PEP-668 for a full discussion of the problems that can occur when multiple installers operate on the same Python install.Therefore, the optimal way is to create a virtual environment, say
MyEnv
, and install packages therein:This will create a directory
$HOME/.venvs/MyEnv
with a configuration filepyvenv.cfg
which includes some details for this virtual environment, such as the Python executable and Python version.Verify the version of the Python in the virtual environment:
The executables of the created virtual environment are found under
$HOME/.venvs/MyEnv/bin
.To install a package into the virtual environment, use
To ‘activate’ the virtual enviroment, i.e. adding its configuration variables into the shell environment, use
Consult Python’s guide to
virtualenv
andpip
at https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments.Debian docs at https://www.debian.org/releases/bookworm/amd64/release-notes/ch-information.en.html#python3-pep-668
Emphasis mine, the docs do talk about application and under that paragraph is second one pointing to installing packages to the virtual environment;
For which @AlQuemist’s answer also highlights ..