Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Behavior of --user in virtualenv #4141

Closed
sjml opened this issue Nov 26, 2016 · 7 comments
Closed

Behavior of --user in virtualenv #4141

sjml opened this issue Nov 26, 2016 · 7 comments
Labels
auto-locked Outdated issues that have been locked by automation

Comments

@sjml
Copy link

sjml commented Nov 26, 2016

  • Pip version: 9.0.1
  • Python version: 2.7.10
  • Operating System: macOS 10.12.1

Description:

I've set up a user-specific pip.conf file to make all installations apply the --user flag, like so:

%> cat ~/.pip/pip.conf
[install]
user = true

This is especially handy in a multi-user system, so individuals can avoid accidentally polluting the global Python installation, but it has a lot of value on a single-user system as well, since it reduces the use of sudo.

When using a standard virtual environment, though, we get the expected error:

(venv) %> pip install flask
Can not perform a '--user' install. User site-packages are not visible in this virtualenv.

It's good to have a warning explaining why this fails, but is there a reason it's not simply ignored altogether? Since the documentation acknowledges that the --user flag has no application in a virtual environment, why not treat it as a no-op? I assume the pip team is smarter than I am, so I'm genuinely curious as to whether its a matter of simpler operation, less surprise, etc.

I know I could make a virtualenv-specific configuration file, but there's no simple way to have it automatically apply to each new virtual environment. #2081 goes over some of this same territory, but it doesn't look like it was ever addressed.

Any insight or persistent solutions would be appreciated; I'm sure this can't be a unique situation.

(Thanks pip team for your great work! Anyone who remembers Python development before pip knows how valuable this project is; the fact that it's taken me this long to run into any issues is a testament to the quality here. 👏 👍 )

@sjml
Copy link
Author

sjml commented Jan 14, 2017

I'm assuming this doesn't merit a response from the team, but if anyone else is interested, I made a very simple shell function that wraps pip, serving as a guard to keep everything user-installed unless you're in a virtual environment.

@sjml sjml closed this as completed Jan 14, 2017
@piotr-dobrogost
Copy link

I'm assuming this doesn't merit a response from the team

I'm pretty sure it does and I agree that --user should be a no-op inside virtualenv. This needs to be solved if pip were to default to --user as described in issue #1668.

@pfmoore
Copy link
Member

pfmoore commented Jan 16, 2017

It sounds reasonable to me that --user should do nothing in a virtualenv (although maybe it should work if the virtualenv has --system-site-packages). I'd be OK with a PR to make this happen.

The reason for slow progress on anything related to --user is that (as far as I know) it's a fairly infrequently used core Python capability, so we don't have a lot of experience with how it works in real life situations. It's a bit of a chicken-and-egg situation, though, so incremental improvements like this in the UX with --user will help.

@piotr-dobrogost
Copy link

piotr-dobrogost commented Jan 16, 2017

As to --user working when --system-site-packages was given to virtualenv; it doesn't look like packages installed with --user are visible in such virtualenv – The --system-site-packages Option

@pfmoore
Copy link
Member

pfmoore commented Jan 16, 2017

I'm not sure that comment's completely clear. I'd be inclined to suggest someone tests it. Also, I don't know if Python 3 "venv" style virtual environments work the same.

In any case, I'd be just as happy to argue that --system-site-packages should see user packages as well. That's one of the many design decisions that probably need to be thrashed out in this area.

@pfmoore
Copy link
Member

pfmoore commented Jan 16, 2017

Update: I just tested and both virtualenv and venv environments can see --user when created with --system-site-packages.

(Interestingly, venv --system-site-packages doesn't install pip into the venv. Possibly because it sees pip is already installed, via the system site-packages, and so skips installing it. It's a debatable point whether this is correct behaviour...)

@piotr-dobrogost
Copy link

Update: I just tested and both virtualenv and venv environments can see --user when created with --system-site-packages.

I raised Document access to --user installed packages in --system-site-packages virtualenv for this.
As to not installing pip I think it should be raised as an issue if only to document this behavior.

alastairpatrick added a commit to alastairpatrick/nopy that referenced this issue Oct 19, 2017
This change is intended to improve isolation by hiding packages installed in other virtual python environments.

It is also an attempt to fix #2.

Virtualenv does not support user site packages directories by default. There is some discussion about it here:

pypa/pip#4141

By using the real python instead of a virtual one (which might be virtualenv) support for user site packages directories should be restored.
@lock lock bot added the auto-locked Outdated issues that have been locked by automation label Jun 3, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jun 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
auto-locked Outdated issues that have been locked by automation
Projects
None yet
Development

No branches or pull requests

3 participants