Python Virtualenv - No module named virtualenvwrapper.hook_loader

Thomas Kremmel picture Thomas Kremmel · Jul 16, 2012 · Viewed 91.7k times · Source

I'm running Mac OS 10.6.8. and wanted to install in addition to python 2.6 also python 2.7 and use python 2.7 in a new virtualenv. I executed the following steps:

I downloaded python 2.7 and installed it:

http://www.python.org/ftp/python/2.7.3/python-2.7.3-macosx10.6.dmg

Then I run the command to setup a new virtualenv using python2.7:

mkvirtualenv --python=python2.7 mynewenv

My .bash_profile looks like the following:

# needed for virtualenvwrapper
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


# Setting PATH for Python 2.7
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
export PATH

Now when I open the console I get the following error message.

ImportError: No module named virtualenvwrapper.hook_loader
virtualenvwrapper.sh: There was a problem running the initialization hooks. If Python could not import the module virtualenvwrapper.hook_loader, check that virtualenv has been installed for VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python and that PATH is set properly.

I also found in a different post that I should upgrade virtualenvwrapper. That did not help.

sudo pip install virtualenvwrapper --upgrade

Any help would be appreciated.

Answer

Thomas Kremmel picture Thomas Kremmel · Jul 16, 2012

The issue was solved following the steps below:

#switch the /usr/bin/python link to point to current python link
cd /usr/bin
sudo mv python python.bak
sudo ln -s /Library/Frameworks/Python.framework/Versions/Current/bin/python python

Re-arrange the export command in order that it is placed before the virtualenv commands in my .bash_profile file:

PATH=/Library/Frameworks/Python.framework/Versions/2.7/bin:$PATH
export PATH

# needed for virtualenvwrapper
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh

Re-Install setuptools, easy install and PIP. This is obviously needed in order that they work properly with the new python version:

sudo sh setuptools-0.6c11-py2.7.egg

sudo easy_install-2.7 pip

pip install virtualenv