5

Using python 3.4.3 with pip 8.1.2 on Cygwin / Windows 7.

I want to maintain one updated system-wide pip rather than having to install and upgrade it for every new venv.

The bundled pip is otherwise quite out of date:

$ python3 -c 'import ensurepip; print(ensurepip.version())'
6.0.8

I don't want to maintain any system-wide modules other than pip, rather all dependencies should land in the venv.

I've tried:

$ pyvenv-3.4 --without-pip venv
$ source venv/bin/activate
(venv) $ which pip python
/usr/bin/pip
$HOME/venv/bin/python

Which is what I expect. But then:

(venv) $ export PIP_REQUIRE_VIRTUALENV=true
(venv) $ pip show pip
Could not find an activated virtualenv (required).

Which is quite confounding.

(venv) $ PIP_REQUIRE_VIRTUALENV= pip show pip
---
Metadata-Version: 2.0
Name: pip
Version: 8.1.2
[...]

If I disable PIP_REQUIRE_VIRTUALENV and run pip install MODULE, pip will run, but the MODULE gets installed in my system site-packages, not under venv.

I did figure a workaround by using --system-site-packages:

$ pyvenv-3.4 --without-pip --system-site-packages venv
$ source venv/bin/activate
(venv) $ export PIP_REQUIRE_VIRTUALENV=true
(venv) $ python -c 'import pip; pip.main()' show pip
---
Metadata-Version: 2.0
Name: pip
Version: 8.1.2

I would rather not take the chance of requirements leaking in from system-wide modules. Is there an easier way? Am I wrong to expect the system pip to 'respect my venv'?

There's a similar question here regarding use of PIP_RESPECT_VIRTUALENV and/or --respect-virtualenv but, I find nothing relevant in the current pip sources.

Community
  • 1
  • 1
Kim Taylor
  • 348
  • 1
  • 10

1 Answers1

0

I also didn't want to install updated version of pip to venv, so used --without-pip. But initially I wanted to reuse some binary modules from the system so I created venv as:

# mkdir ~/.venv

# pip index versions ansible
ansible (7.3.0)

# python3 -m venv --without-pip --system-site-packages ansible-7.3.0

pip is not in ~/.venv/.../bin, system pip tells cannot install to system dir so install to user dir (~/.local/share/).

There is a way to use venv pip by running it as module inside venv (which is available because of --system-site-packages):

python -m pip install --require-virtualenv ansible==7.3.0
gavenkoa
  • 45,285
  • 19
  • 251
  • 303