Setting up Python venv in Mac OSX (Lion), why didn't `which python` change?

572 Views Asked by At

I'm trying to follow this guide to set up Virtual Environments on OSX 10.8.5 (Lion). Homebrew is successfully installed, and the following updates completed successfully:

$ pip install --upgrade distribute  
$ pip install --upgrade pip 

However, which python still shows /Library/Frameworks/Python.framework/Versions/2.7/bin/python. Why?? (I expected /usr/local/bin/python instead, and the goal is to use venv(s) to separate projects.)

Updates...
$PATH information:

host:~ username$ echo $PATH
 /Library/Frameworks/Python.framework/Versions/2.7/bin:/Library/
 Frameworks/Python.framework/Versions/3.4/bin:/usr/bin:/bin:/usr/
 sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/local/git/bin 
host:~ username$  

Turns out ... host:~ user$ brew install python Updating Homebrew... ==> Auto-updated Homebrew! Updated 1 tap (homebrew/core). No changes to formulae.

Warning: python-2.7.13 already installed, it's just not linked.

Running doctor showed a number of problems, but the solution would be... host:~ user$ brew link python

This ultimately required a force (--overwrite) ...

For references: brew install python, but then: "python-2.7.6 already installed, it's just not linked" python homebrew by default

However I don't understand why this happened. If someone can explain what happened (why homebrew didn't update the link), I'm happy to award an answer.

1

There are 1 best solutions below

2
2ps On

If your PATH in OS X doesn’t point to /usr/local/bin first, you have to set up your virtualenv using the -p option, which allows you to specify the path to the python interpreter that you want to use within the virtualenv:

cd /path/to/project
virtualenv . -p /usr/local/bin/python
. bin/activate
python --version