0

I'm using Python 2.7.14 installed through Homebrew on MacOS. How do I stop this happening?:

$ virtualenv --no-site-packages venv
New python executable in /private/tmp/venv/bin/python2.7
Also creating executable in /private/tmp/venv/bin/python
Installing setuptools, pip, wheel...done.
$ . venv/bin/activate
(venv) $ pip --version
pip 9.0.1 from /usr/local/lib/python2.7/site-packages (python 2.7)

What I expected

$ env -i PATH=/tmp/venv/bin pip --version
pip 9.0.1 from /private/tmp/venv/lib/python2.7/site-packages (python 2.7)

EDIT: Solution related Why does virtualenv inherit $PYTHONPATH from my shell?

A T
  • 13,008
  • 21
  • 97
  • 158
  • What version of virtualenv are you on? (--no-site-packages is now the default behaviour so it shouldn't be needed) – qff Dec 07 '17 at 12:33
  • virtualenv 15.1.0. Yeah I just wanted to be super sure that no site packages were being used. – A T Dec 07 '17 at 12:38
  • I have the exact same setup as you and it works perfectly fine for me. For a second I thought it was some weird conflict with `/private/tmp` but I just don't get the same problem – qff Dec 07 '17 at 12:43
  • 1
    What does `echo $PATH` say when you're in the virtualenv? – qff Dec 07 '17 at 12:44
  • `pip` is special, virtualenv creates a copy of that even if you use `--no-site-packages` – tripleee Dec 07 '17 at 12:46
  • Figured it out. Had to `unset PYTHONPATH` in my bin/activate – A T Dec 07 '17 at 12:50

1 Answers1

1

I edited venv/bin/activate with this line:

unset PYTHONPATH
vvvvv
  • 25,404
  • 19
  • 49
  • 81
A T
  • 13,008
  • 21
  • 97
  • 158