Skip to content

python and virtualenv problems after Mountain Lion upgrade

Mountain Lion (Mac OS X 10.8) moved my cheese in the form of the following error:

Traceback (most recent call last):
File "<string>", line 1, in <module>
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.

Which was a bit confusing for me. Recalling that /usr/local is basically all homebrew, and that homebrew relies on system libs, I confirmed:

$ which python | xargs ls -l
lrwxr-xr-x 1 root wheel 60 Feb 6 21:44 /usr/local/bin/python -> /Library/Frameworks/Python.framework/Versions/2.7/bin/python

So yes: system python. There was probably some combination of stuff from /usr getting removed and my PATH changes that conspired to break things. So let’s put them back, or at least get things put in place that will make everything usable again:

$ sudo /usr/local/bin/easy_install-2.7 distribute
Traceback (most recent call last):
File "/usr/local/bin/easy_install-2.7", line 5, in <module>
from pkg_resources import load_entry_point
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 2603, in <module>
working_set.require(__requires__)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 666, in require
needed = self.resolve(parse_requirements(requirements))
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 565, in resolve
raise DistributionNotFound(req) # XXX put more info here
pkg_resources.DistributionNotFound: distribute==0.6.24

Errr. Well perhaps we’re still getting confusion about what’s getting called from where, so let’s be very explicit:

$ sudo /usr/local/bin/python2.7 /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/easy_install.py distribute
Searching for distribute
Reading http://pypi.python.org/simple/distribute/
Reading http://packages.python.org/distribute
Best match: distribute 0.6.28
[snipped]
Installed /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/distribute-0.6.28-py2.7.egg
Processing dependencies for distribute
Finished processing dependencies for distribute

Cool! Progress!

$ sudo /usr/local/bin/python2.7 /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/easy_install.py pip
Searching for pip
Reading http://pypi.python.org/simple/pip/
Reading http://pip.openplans.org
Reading http://www.pip-installer.org
Best match: pip 1.1
[snipped]
Installed /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-1.1-py2.7.egg
Processing dependencies for pip
Finished processing dependencies for pip

Awesome: we can haz pip.

$ sudo /usr/local/bin/python2.7 /Library/Frameworks/Python.framework/Versions/2.7/bin/pip-2.7 install virtualenvwrapper
Downloading/unpacking virtualenvwrapper
Downloading virtualenvwrapper-3.5.tar.gz (465Kb): 465Kb downloaded
Running setup.py egg_info for package virtualenvwrapper
[snipped]
Successfully installed virtualenvwrapper virtualenv virtualenv-clone
Cleaning up...

So are we all set?

$ . .profile && echo "huzzah"
huzzah

Looks like yes. :)

{ 1 } Comments

  1. Matt | 3 April 2013 at 19:26 | Permalink

    I found this really helpful. It’s also the first google search result for the error. Thx Mr. Palmer.

Post a Comment

Your email is never published nor shared. Required fields are marked *



This work by tarheelcoxn is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 United States.