A T A T - 1 year ago 72
Python Question

Force virtualenv pip to be used

Running Ubuntu 16.10 with Python 2.7.12+ (default one) and virtualenv 15.0.3 (

sudo -H pip install virtualenv
). What am I doing wrong?

$ virtualenv a && . "$_"/bin/activate && pip --version
New python executable in /tmp/a/bin/python
Installing setuptools, pip, wheel...done.
pip 9.0.0 from /usr/local/lib/python2.7/dist-packages (python 2.7)
$ /tmp/a/bin/pip --version
pip 9.0.0 from /usr/local/lib/python2.7/dist-packages (python 2.7)
$ /tmp/a/bin/python -c 'from pip import __file__; print __file__'

Answer Source

Have you tried calling $venv/bin/python $venv/lib/site-packages/pip/__main__.py? That should work.

To find out why the wrong pip is being called, you should look at:

  • $PATH, what order is it, which pip and which python will also help
  • sys.path, what order is it, does /usr/local/lib/ appear before the venv
  • $PYTHONPATH, which affects sys.path
  • possible symlinks in the venv, which could point outside the venv