Reputation: 1873
Why does $ mkvirtualenv test
use the system python (v2.7.6) instead of the brew-ed python (2.7.8) and how do I configure virtualenvwrapper to use the desired python?
I'm using OS X 10.9.5 with a homebrew install of python (v2.7.8). I have a system wide install of virtualenv and virtualenvwrapper. My shell is ZSH via oh-my-zsh using the virtualenvwrapper plugin (although I've tried pulling out the plugin and sourcing virtualenvwrapper.sh manually and I get the same behavior).
This 2.7.8 is the python interpreter I get from a shell
$ echo $PATH
/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin
$ which python
/usr/local/bin/python
$ python
Python 2.7.8 (default, Aug 24 2014, 21:26:19)
...
I have the following environment set in at the top of my .zshrc (before virtualenvwrapper is sourced) and have matched them all to the output of $ printenv
to confirm they are getting set correctly
export PATH="/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin"
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Projects/Python
# this is the location shown above to be v2.7.8
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv
export PIP_DOWNLOAD_CACHE=$HOME/.pip/download_cache
export PIP_VIRTUALENV_BASE=$WORKON_HOME
Despite the correct $PATH and the explicit override to use the python interpreter I know is v2.7.8 any mkproject gets the default system python:
$ mkvirtualenv test
....
(test)$ python
Python 2.7.6 (default, Mar 18 2014, 15:05:23)
...
I have found an infuriating (in that it seems it should change nothing yet does) work around
$ mkvirtualenv -p `which python` test
...
(test)$ python
Python 2.7.8 (default, Aug 24 2014, 21:26:19)
...
So why in the world are these environment variables not getting used despite being set and it having the clear possibility of working as shown in the work around??
Upvotes: 3
Views: 779
Reputation: 3335
By default, virtualenv
will use the python binary it was installed with, not the python binary that shows up first in the path.
virtualenv --help
...
-p PYTHON_EXE, --python=PYTHON_EXE
The Python interpreter to use, e.g.,
--python=python2.5 will use the python2.5 interpreter
to create the new environment. The default is the
interpreter that virtualenv was installed with
(/usr/bin/python)
Your best bet is probably to uninstall virtualenvwrapper
and then reinstall it with the pip living in your brewed Python's install directory.
Upvotes: 1