Should pip install --user install in a venv install to the global user path?

I started wondering this when replying to pypa/pip#7438. The current behaviour is:

$ pip install ...                # A: installs to global, system path
$ pip install --user ...         # B: installs to global, user path
(venv) $ pip install ...         # C: installs to venv
(venv) $ pip install --user ...  # D: installs to global, user path

Scenario D feels quite weird to me; I’d expect it to install to my venv.

1 Like

Scenario D feels quite weird to me; I’d expect it to install to my venv.

For me the current behaviour feels the sane path :thinking: User is a specifier of the site package location, so should install into there. I’d be ok for pip to refuse to do the install though under that circumstance.

That’s a bug that’s been fixed on master.

https://github.com/pypa/pip/pull/7155

This was brought up over an year ago on the issue tracker, and seems to have been the behavior since PEP 405 (venv module) was rolled out.

1 Like

I would expect (venv) $ pip install --user to fail with an error message. Virtual environment were not a thing when I wrote PEP 370 about 12 years ago. Otherwise I would have specified that the --user option does not make any sense from within a virtual environment.

PEP 405 specifies that a user site directory is considered a global site-package directory. By default packages installed with (venv) $ pip install --user are not available from the virtual environment.

1 Like

It will (in pip 20.1). The confusion here is that there was a long-standing bug that meant that only happened for virtualenv-based environments, and not for venv-based ones. That has now been fixed, but the fix isn’t yet in a released version of pip.

5 Likes