From virtualenvwrapper to pyenv-virtualenvwrapper (OSX)

SEE -->

Now that Python3 can't be ignored, we come to the conclusion that we have to change Python versions a lot.

With this setup you'll still be able to use "WORKON <env>" but that env now has a pinned Python version.
And this Python version is easy installable.

First install all the needed packages with Homebrew:

$ brew install pyenv pyenv-virtualenv pyenv-virtualenvwrapper zlib sqlite

Also this Python package needs to be installed:


$ pip install virtualenvwrapper --user

Add the following to your ~/.bashrc:

# For compilers to find zlib you may need to set:
export LDFLAGS="${LDFLAGS} -L/usr/local/opt/zlib/lib"
export CPPFLAGS="${CPPFLAGS} -I/usr/local/opt/zlib/include"
# For pkg-config to find zlib you may need to set:
export PKG_CONFIG_PATH="${PKG_CONFIG_PATH} /usr/local/opt/zlib/lib/pkgconfig"
if which pyenv > /dev/null; then eval "$(pyenv init -)"; fi
if which pyenv-virtualenv-init > /dev/null; then eval "$(pyenv virtualenv-init -)"; fi
pyenv virtualenvwrapper

Note that you might have to remove these old lines of your ~/.bashrc:

# export WORKON_HOME=$HOME/.virtualenvs
# source /usr/local/bin/

Installing Python versions (this can take awhile):

$ pyenv install 2.7.10
$ pyenv install 3.4.3


Creating a new virtualenv with Python 2.7.10:

$ mkvirtualenv my-virtualenv2710 -p ~/.pyenv/versions/2.7.10/bin/python

Creating a new virtualenv with Python 3.4.3:

$ mkvirtualenv my-virtualenv343 -p ~/.pyenv/versions/3.4.3/bin/python

To see what Python version is used in this environment:

$ python --version

To show what Python version you're using on your project you can create a .python-version file in the root of your project:

$ cd /path/to/root/of/your/project
$ pyenv local 3.4.3

To activate a virtualenv:

$ workon my-virtualenv2710

Removing an existing virtualenv:

$ rmvirtualenv my-virtualenv2710

Trouble shooting:

In case:

OSError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/xxxx'


$ sudo chown -R $USER /Library/Python/2.7