None of these worked. I installed Python3 first when setting up my osx machine, and pip and all default to that.
First, check which python you have installed:
$ `which python` -V
If this returns "Python 2.7.12", then you are set to run:
$ mkvirtualenv -p `which python` api_server
Running virtualenv with interpreter /usr/local/bin/python
New python executable in /Users/eric/.virtualenvs/api_server/bin/python2.7
Also creating executable in /Users/eric/.virtualenvs/api_server/bin/python
Installing setuptools, pip, wheel...done.
virtualenvwrapper.user_scripts creating /Users/eric/.virtualenvs/api_server/bin/predeactivate
virtualenvwrapper.user_scripts creating /Users/eric/.virtualenvs/api_server/bin/postdeactivate
virtualenvwrapper.user_scripts creating /Users/eric/.virtualenvs/api_server/bin/preactivate
virtualenvwrapper.user_scripts creating /Users/eric/.virtualenvs/api_server/bin/postactivate
virtualenvwrapper.user_scripts creating /Users/eric/.virtualenvs/api_server/bin/get_env_details
This will also activate the api_server
workon, which changes your python executable:
$ which python
/Users/eric/.virtualenvs/api_server/bin/python
$ python -V
Python 2.7.12
What does which python
actually do? It outputs the directory of the python executables found in your PATH:
$ which python
/usr/local/bin/python
By using which python
, you are basically passing in /usr/local/bin/python
to the -p
option in the mkvirtualenv directory.
What happens when you have more than one python executable returned in which python
? Just find the one you want and pass it in:
$ mkvirtualenv -p /usr/local/bin/python3 api_server
And virtualenvwrapper will end up using that python executable instead.
port select ...
and sticking with your base 2.7, does just runningmkvirtualenv --python /path/to/python2.6
work? It should automatically switch to (and set up the environment with) the correct interpreter. On my system (set up with homebrew),mkvirtualenv -p python2.6
works fine. – Lefloremkvirtualenv --python /path/to/python2.6 env_name
. mkvirtualenv makes a folder called "env_name" in your$WORKON_HOME
, which gets passed on to virtualenv as itsDEST_DIR
argument. Without specifying a name, it would have a hard time figuring out where to set things up, that's for sure. – Leflore