Fix Python – pip installing in global site-packages instead of virtualenv


Asked By – DocZerø

Using pip3 to install a package in a virtualenv causes the package to be installed in the global site-packages folder instead of the one in the virtualenv folder. Here’s how I set up Python3 and virtualenv on OS X Mavericks (10.9.1):

I installed Python3 using Homebrew:

ruby -e "$(curl -fsSL"
brew install python3 --with-brewed-openssl

Changed the $PATH variable in .bash_profile; added the following line:

export PATH=/usr/local/bin:$PATH

Running which python3 returns /usr/local/bin/python3 (after restarting the shell).

Note: which python3 still returns /usr/bin/python though.

Installed virtualenv using pip3:

pip3 install virtualenv

Next, create a new virtualenv and activate it:

virtualenv testpy3 -p python3
cd testpy3
source bin/activate

Note: if I don’t specify -p python3, pip will be missing from the bin folder in the virtualenv.

Running which pip and which pip3 both return the virtualenv folder:


Now, when I try to install e.g. Markdown using pip in the activated virtualenv, pip will install in the global site-packages folder instead of the site-packages folder of the virtualenv.

pip install markdown

Running pip list returns:

Markdown (2.3.1)
pip (1.4.1)
setuptools (2.0.1)
virtualenv (1.11)

Contents of /Users/kristof/VirtualEnvs/testpy3/lib/python3.3/site-packages:


Contents of /usr/local/lib/python3.3/site-packages:


As you can see, the global site-packages folder contains Markdown, the virtualenv folder doesn’t.

Note: I had Python2 and Python3 installed before on a different VM (followed these instructions) and had the same issue with Python3; installing packages in a Python2 based virtualenv worked flawlessly though.

Any tips, hints, … would be very much appreciated.

Now we will see solution for issue: pip installing in global site-packages instead of virtualenv


Funny you brought this up, I just had the exact same problem. I solved it eventually, but I’m still unsure as to what caused it.

Try checking your bin/pip and bin/activate scripts. In bin/pip, look at the shebang. Is it correct? If not, correct it. Then on line ~42 in your bin/activate, check to see if your virtualenv path is right. It’ll look something like this


If it’s wrong, correct it, deactivate, then . bin/activate, and if our mutual problem had the same cause, it should work. If it still doesn’t, you’re on the right track, anyway. I went through the same problem solving routine as you did, which piping over and over, following the stack trace, etc.

Make absolutely sure that


is what you want, and not referring to another similarly-named test project (I had that problem, and have no idea how it started. My suspicion is running multiple virtualenvs at the same time).

If none of this works, a temporary solution may be to, as Joe Holloway said,

Just run the virtualenv’s pip with its full path (i.e. don’t rely on searching the executable path) and you don’t even need to activate the environment. It will do the right thing.

Perhaps not ideal, but it ought to work in a pinch.

Link to my original question:

VirtualEnv/Pip trying to install packages globally

This question is answered By – Chase Ries

This answer is collected from stackoverflow and reviewed by FixPython community admins, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0