pip: Pip should not apply PEP668 to user local installation.
Description
Since PEP 668 implementation (on Arch linux at least), Pip refuses to install a package in the user local directory. Instead, it returns the error message specified by the PEP:
× This environment is externally managed
╰─> To install Python packages system-wide, try 'pacman -S
python-xyz', where xyz is the package you are trying to
install.
If you wish to install a non-Arch-packaged Python package,
create a virtual environment using 'python -m venv path/to/venv'.
Then use path/to/venv/bin/python and path/to/venv/bin/pip.
If you wish to install a non-Arch packaged Python application,
it may be easiest to use 'pipx install xyz', which will manage a
virtual environment for you. Make sure you have python-pipx
installed via pacman.
Expected behavior
User local package, is by definition not “system package”. As such, it is outside the scope of PEP 668. There is not even a way to install a package in there without pip.
Suggested work-arounds includes:
- use
--break-system-packages
: unsatisfactory and misleading - use a virtual environment: only satisfactory if the package is installed for a particular project, not for general use in the system
As I said, ~/.local/lib/python3.11 is not a system directory, there is no reason to protect it against pip installation, and since the whole point of this directory was to install packages with pip, the current state is contradictory.
pip version
23.1.2
Python version
3.11.3
OS
Arch Linux
How to Reproduce
- Get the last version of Python and Pip on an arch install with pacman
sudo pacman -S python python-pip
- Try to install a package that is not available in repositories
pip install --user ipympl
Output
$ pacman -Ss ipympl $ pip install --user ipympl error: externally-managed-environment
× This environment is externally managed ╰─> To install Python packages system-wide, try ‘pacman -S python-xyz’, where xyz is the package you are trying to install.
If you wish to install a non-Arch-packaged Python package,
create a virtual environment using 'python -m venv path/to/venv'.
Then use path/to/venv/bin/python and path/to/venv/bin/pip.
If you wish to install a non-Arch packaged Python application,
it may be easiest to use 'pipx install xyz', which will manage a
virtual environment for you. Make sure you have python-pipx
installed via pacman.
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.
Code of Conduct
- I agree to follow the PSF Code of Conduct.
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 17 (11 by maintainers)
This isn’t really the right venue to delve into changing the PEP anyways. pip correctly implements the spec. If you disagree with the spec, discuss.python.org is the right place to discuss it, and if there’s some broad agreement then writing a PEP to update it.
Another sad thing is that they will blame pip for this change. We’re very much “piggy in the middle” here, and we apparently can’t please everyone, so all we can do is follow the agreed standards, which is what we’ve done.