I'm using virtualenv
and pip
on Debian Wheezy. I'm having an odd problem where packages appear to install OK, but then aren't visible in the virtualenv.
This is my requirements.txt
file:
Django==1.7.7
psycopg2==2.5.4
django-geojson==2.6.0
If I install it with pip
from inside my virtualenv, it says everything has been installed:
(.venv)$ sudo pip install -r requirements.txt
Requirement already satisfied (use --upgrade to upgrade): Django==1.7.7 in /usr/local/lib/python2.7/dist-packages (from -r requirements/base.txt (line 1))
Requirement already satisfied (use --upgrade to upgrade): psycopg2==2.5.4 in /usr/local/lib/python2.7/dist-packages (from -r requirements/base.txt (line 2))
Requirement already satisfied (use --upgrade to upgrade): django-geojson==2.6.0 in /usr/local/lib/python2.7/dist-packages (from -r requirements/base.txt (line 3))
Requirement already satisfied (use --upgrade to upgrade): six in /usr/local/lib/python2.7/dist-packages (from django-geojson==2.6.0->-r requirements/base.txt (line 3))
Cleaning up...
But then if I do pip freeze
to check what is installed, it looks like pip
thinks I have a completely different set of packages, and in particular it doesn't see djgeojson
there:
(.venv)$ pip freeze
Django==1.7.4
argparse==1.2.1
coverage==3.7.1
distribute==0.6.24
django-debug-toolbar==1.2.1
gunicorn==19.3.0
psycopg2==2.5.4
requirements==0.1
setproctitle==1.1.8
sqlparse==0.1.14
wsgiref==0.1.2
And if I fire up a Python terminal, Python can't see djgeojson
.
Why is this happening? It is quite confusing.
Your problem is that you've installed requirements with sudo and they were installed in your system python library folder instead and not in your virtual environment's
venv
library.What to do? Run the same command but this time without sudo:
pip install -r requirements.txt
. This will run pip from the virtual environment and install packages to the right place.When you activate a virtual environment e.q with
source path/to/my/venv/bin/acivate
the path variable$PATH
of your current user is updated and then when you run something with sudo, this new $PATH that you've just updated when activating the virtual environment is no longer the same. Same thing happens when you open a new shell window or logs in as a different user withsu
or runningsudo
,$PATH
variable is not a global system one.