What’s the right way for NORMAL users to install Python packages now? Weirdos like me who have a dozen different Pythons installed, mostly from source, don’t count; what are regular ordinary people supposed to do? In theory, it’s supposed to be possible to perform user installations, but I’ve run into this problem and don’t know what to advise.
Note: The true use-case for this is my brother’s Debian system, but that’s a messy one that has been upgraded several times and has a ton of other stuff going on, but I can recreate the issue on a tiny Debian VM, so that’s what I’ll be using here.
Install a vanilla Debian Bookworm (current stable, v12.1) using the standard netinst ISO.
rosuav@debian:~$ sudo apt install python3-pip --no-install-recommends
...
...
Setting up python3-lib2to3 (3.11.2-3) ...
Setting up python3-distutils (3.11.2-3) ...
Setting up python3-setuptools (66.1.1-1) ...
Setting up python3-wheel (0.38.4-2) ...
Setting up python3-pip (23.0.1+dfsg-1) ...
Processing triggers for man-db (2.11.2-2) ...
rosuav@debian:~$ pip install pepotron
error: externally-managed-environment
× This environment is externally managed
╰─> To install Python packages system-wide, try apt install
python3-xyz, where xyz is the package you are trying to
install.
If you wish to install a non-Debian-packaged Python package,
create a virtual environment using python3 -m venv path/to/venv.
Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make
sure you have python3-full installed.
If you wish to install a non-Debian packaged Python application,
it may be easiest to use pipx install xyz, which will manage a
virtual environment for you. Make sure you have pipx installed.
See /usr/share/doc/python3.11/README.venv for more information.
note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.
rosuav@debian:~$ pip --version
pip 23.0.1 from /usr/lib/python3/dist-packages/pip (python 3.11)
In contrast, here’s what my own system does:
rosuav@sikorsky:~$ python3 -m pip install -U pepotron
Defaulting to user installation because normal site-packages is not writeable
...
WARNING: The scripts bpo and pep are installed in '/home/rosuav/.local/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed pepotron-1.0.0
rosuav@sikorsky:~$ python3 -m pip --version
pip 23.1.1 from /home/rosuav/.local/lib/python3.12/site-packages/pip (python 3.12)
(had to specify -U since I already have pepotron installed, but that shouldn’t affect things)
The vanilla system won’t install into the user directory even if explicitly given the --user
parameter. How do I reenable user installations? Preferably with the automatic “can’t write to site-packages, doing a user installation instead” logic, which makes it perfectly smooth.