Skip to content

pip.conf user = true conflicts with venv #8977

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

Closed
bernd-wechner opened this issue Oct 10, 2020 · 10 comments
Closed

pip.conf user = true conflicts with venv #8977

bernd-wechner opened this issue Oct 10, 2020 · 10 comments

Comments

@bernd-wechner
Copy link

Environment

  • pip version: 20.2.3
  • Python version: 3.8.5
  • OS: Mint 20

Description

If pip.conf contains the user = true instruction then attempting to run pip in a venv results in:

ERROR: Can not perform a '--user' install. User site-packages are not visible in this virtualenv.

I could find not command line option that is the oppposite of user (i.e. disables the pip.conf set user = true and so had to edit pip.conf in order to install packages into a venv with pip.

Expected behavior

I'd expect not to have to edit pip.conf. If pip is run from within a venv and is aware it's in a venv how about silently ignoring the --user option? Or providing a command line option like --nouser to request it be ignored. That way Makefiles that implement venvs don't bomb on a local dev system which by default has user = true (which after all is recommended ... as we're working desktop environments that have loads of Python code and fiddling with system libs is not recommended, we leave that to Ubuntu or our distro to do, and use user = true to do our Python dev work)

How to Reproduce

Add user = true to pip.conf (in ~/.config/pip/pip.conf on Ubuntu systems) and then create and activate a venv and try to install package with pip.

Output

ERROR: Can not perform a '--user' install. User site-packages are not visible in this virtualenv.
@McSinyx
Copy link
Contributor

McSinyx commented Oct 10, 2020

FYI there's a --no-user flag. Whyever pip reads its real config in a virtual environment, I recall stumbling upon the discussion but cannot find it at the moment.

@uranusjr
Copy link
Member

pip has real config in a virtual environment, at $(sys.prefix)/pip.conf. Having a user = false there would override the user configuration.

@uranusjr
Copy link
Member

#4141 has relevent discussions. (Probably not the one you’re thinking about, there are several threads on this.)

@bernd-wechner
Copy link
Author

FYI there's a --no-user flag. Whyever pip reads its real config in a virtual environment, I recall stumbling upon the discussion but cannot find it at the moment.

Apparently not (anymore if it ever did).

pip has real config in a virtual environment, at $(sys.prefix)/pip.conf. Having a user = false there would override the user configuration.

That works though to be more precise it has to be:

[install]
user = false

and this rather esoteric feature could be more accessibly documented. But the fault there lies with venv not pip I suspect.

Creating a new venv should really just create this file given they are in conflict otherwise.

@McSinyx
Copy link
Contributor

McSinyx commented Oct 10, 2020

pip has real config in a virtual environment, at $(sys.prefix)/pip.conf

I suppose you meant virtual config 😄 (or config exclusively for the virtual environment, because my metaphor game suck 😞). Also thanks for the pointer, it's not what I was looking for but interesting discussion indeed.

Apparently not (anymore if it ever did).

I'm pretty sure that it exists and I have suggested this in another thread not so long ago. Try pip install --no-user .... As you pointed out earlier, it's an install-specific option.

@pradyunsg
Copy link
Member

FYI there's a --no-user flag.

This is not a supported end-user flag. Please don't use this.

@McSinyx
Copy link
Contributor

McSinyx commented Oct 10, 2020

Ah, thanks for the information. I was about to ask why but found GH-5116. I'll stop suggesting it to others but you can't stop me from using it myself 😈

Edit: jokes aside, could you share which situation led you to have user = true in your pip.conf, @bernd-wechner? Such behavior has been default in Debian-based distros for as long as I can remember until upstream pip provides a smarter fallback mechanism, which essentially installs to users' site the majority of the times.

@bernd-wechner
Copy link
Author

could you share which situation led you to have user = true in your pip.conf

it came recommended, more than once, in different contexts now. I do active Python development on an Ubuntu derived system (Mint) and the Desktop Environment and other system utilities are increasingly Python dependent.

I have broken elements of my desktop before by keeping system Python libs up to date. I've been warned NEVER To do sudo pip install. Without sodo pip fails unless you specify --user. Given this (common I'd have thought) use case making --user the default is sensible indeed.

The short answer is: I've been told in no uncertain terms NEVER to do sudo pip install and always pip install --user (or of course always use a venv).

@pfmoore
Copy link
Member

pfmoore commented Oct 10, 2020

Without sudo pip fails unless you specify --user

It shouldn't (assuming a recent pip). If site-packages isn't writeable, pip falls back to user site automatically. The recommendations you have seen are basically out of date and flawed, as you found out. (Never using sudo with pip is 100% correct advice, though 🙂) Unfortunately, it's hard to get rid of out of date information on the internet 🙁

@bernd-wechner
Copy link
Author

Without sudo pip fails unless you specify --user

It shouldn't (assuming a recent pip). If site-packages isn't writeable, pip falls back to user site automatically. The recommendations you have seen are basically out of date and flawed, as you found out. (Never using sudo with pip is 100% correct advice, though slightly_smiling_face) Unfortunately, it's hard to get rid of out of date information on the internet slightly_frowning_face

Thanks for clarifying! pip evolves! And yes on-line advice can't always keep up with the sometimes impressive rate of improvement of FOSS! Alas. But it's a simple consequence of the FOSS boom methinks and how awesomely it marches forward.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants