Error message for virtualenvwrapper on Mac OS X Yosemite 10.10.3

user1499532 picture user1499532 · Apr 19, 2015 · Viewed 12.3k times · Source

I recently did a clean install of Mac OS 10.10.3 and am trying to set up a python environment. But I can't get virtualenvwrapper to work.

I installed python 2 and 3 using Homebrew.

$ which python
/usr/local/bin/python

$ which python3
/usr/local/bin/python3

$ which pip
/usr/local/bin/pip

$ which virtualenv
/usr/local/bin/virtualenv

$ which virtualenvwrapper.sh
/usr/local/bin/virtualenvwrapper.sh

Here are the lines in my .bash_profile

export PATH=/usr/local/bin:$PATH
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv
source /usr/local/bin/virtualenvwrapper.sh

The virtualenv works on its own with: $ source bin/activate

But when I source the virtualenvwrapper.sh. I get the following error message.

/usr/local/opt/python/bin/python2.7: No module named virtualenvwrapper
virtualenvwrapper.sh: There was a problem running the initialization hooks. 

If Python could not import the module virtualenvwrapper.hook_loader,
check that virtualenvwrapper has been installed for
VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python and that PATH is
set properly.

I can't figure out what went wrong. When I echo VIRTUALENVWRAPPER_PYTHON in the terminal. It returns the right path. In fact, all my paths are correct. They all point to the homebrew directory.

How can I get it to work?

Answer

lionHeart picture lionHeart · Apr 17, 2017

It has been some time since this question was asked, but encountering the same issue, I'd like to add my solution in case someone might find it usefull:

Since virtualenvwrapper was installed using Python3, it is axpected that VIRTUALENVWRAPPER_PYTHON variable will point to Python3 path and not the Python2 path.

That is, in .bash_profile change:
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python

To:
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3

Then you can start using virtualwrapper, even if not installed for Python2 (unless you want to explicitly create the environment using Python2 in which case you'd probebly have to install it using pip2 and specify the relevant python path on the virtual environment creation command).