pip ignores the site.ENABLE_USER_SITE value if user is set explicitly (asymetric with venv behaviour)
See original GitHub issueEnvironment
- pip version: 20.2.0 & master
- Python version: all
- OS: all
Description
When we have a venv or virtualenv, and site.ENABLE_USER_SITE
is False
, and try to pip install --user
and error is raised (InstallationError
). If we do the same with a non-virtual environment, the ENABLE_USER_SITE
value is ignored.
$ python -m venv /tmp/venv
$ source /tmp/venv/bin/activate
(venv) $ PYTHONNOUSERSITE=1 pip install --user typing-extensions
ERROR: Can not perform a '--user' install. User site-packages are not visible in this virtualenv.
But with a base environment (i.e. not virtual):
(venv) $ deactivate
$ PYTHONNOUSERSITE=1 pip -v install --user typing-extensions
Using pip 20.2.2 from /usr/local/lib/python3.8/site-packages/pip (python 3.8)
User install by explicit request
...
Collecting typing-extensions
Using cached typing_extensions-3.7.4.3-py3-none-any.whl (22 kB)
Installing collected packages: typing-extensions
Successfully installed typing-extensions-3.7.4.3
Expected behavior
I expect the site.ENABLE_USER_SITE
to always be honoured
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
Pip default behavior conflicts with virtualenv? - Stack Overflow
When I got to virtualenv flask command, I received this error message: Can not perform a '--user' install. User site-packages are not visible...
Read more >venv — Creation of virtual environments — Python 3.11.1 ...
When a virtual environment has been activated, the VIRTUAL_ENV environment variable is set to the path of the environment. Since explicitly activating a...
Read more >How can I block pip and python user packages
If this is set, Python won't add the user site-packages directory to sys.path. So even though I was surprised by the behaviour, I...
Read more >Pipenv: A Guide to the New Python Packaging Tool
Otherwise, Pipenv will use whatever default virtualenv finds. Sidenote: If you require a more specific version of Python, you can provide a --python...
Read more >Advanced Usage of Pipenv - Python Packaging Authority
Pipenv will expand environment variables (if defined) in your Pipfile. ... To reuse Conda–installed Python packages, use the --site-packages flag: $ pipenv ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think this depends on your interpretation to “disabled”. Does it mean that no Python tools can/should put stuffs inside the site, or simply that Python won’t load it into
sys.path
for import? pip’s current behaviour basically means that it’s installing into a location that’s neither discoverable nor importable (by default), i.e. implying the second interpretation.IMO the linked Superuser question is fundamentally misguided. The only way to really prevent users from
pip install
-ing stuff into their user directories is to disable their filesystem write permission, since pip can always install to any arbitrary locations by specifying--prefix
and--target
. The--user
option is not any different. The reason pip explicitly errors out inside a virtual environment is for UX reasons (a pip inside venv is not supposed to be able to modify the non-venv interpreter), and the same UX problem does not exist forsite.ENABLE_USER_SITE = False
since the installed packages are not visible anyway.(To be explicit: I’m not saying your interpretation is wrong, just that pip’s behaviour is also not unreasonable.)
Honestly I doubt the initial implementation actually put much thought in comparing approaches, and simply went with the most simplistic one (the current behaviour). I would welcome a PR containing a change of behaviour, with accompanying documentation explaining the thought process.