Python packages not installing in virtualenv using pip
Solution 1:
The problem here is that you're using sudo
when you shouldn't be. And that's causing pip
to try to install into /usr/local/lib
instead of ~/glenv/lib
. (And, because you used sudo
, it's successfully doing so, but that doesn't help you, because you're not allowing system site-packages in your venv.)
There are multiple reasons sudo pip
could lead to this behavior, but the most likely is this: On most systems (including the various Mac and RHEL/CentOS boxes I have immediate access to), the sudoers
file will reset your environment, then add back in a handful of whitelisted environment variables. This means that when you sudo pip
, it will not see the environment variables that virtualenv
sets up, so it will fall back to doing the default thing and install into your system Python, instead of your venv.
But really, it doesn't matter why this is happening. The answer is the same: just do pip install
instead of sudo pip install
.
Note that you also want to remove the sudo
on the virtualenv
call, as this will probably cause the venv to be set up incorrectly (which is why you need the sudo chmod
, which wouldn't be necessary otherwise). The whole point of installing things under your user home directory is that you can do it with your normal user permissions.
As a side note, you also may want to upgrade to a newer virtualenv
/pip
, as 1.8 and 1.2 have some bug fixes and improvements. But I verified that I get exactly the same problem as you even with the latest (1.8.4 and 1.2.1) versions, so I don't think that's relevant here.