Python pip broken after OS X 10.8 upgrade

Question:

Made the upgrade to Mac OS X 10.8 (Mountain Lion) and get now the following error when trying to call $ pip:

Traceback (most recent call last):
  File "/usr/local/bin/pip", 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: pip==1.1

Update: Tried to reinstall by doing the install procedure again (with http://www.pip-installer.org/en/latest/installing.html#using-the-installer and easy_install), but didn’t work, got the same error.

Tried now the following: Calling $ sudo pip and the above error disappears. Strange is, that the directories which could not befound in the above error message point to /System/Library/… while the python installation is (new ?) to find in /Library/Frameworks/..:

$ which python
/Library/Frameworks/Python.framework/Versions/Current/bin/python

Any idea how to get rid of the sudo?

Asked By: geo_so

||

Answers:

Use easy_install to update your pip to the latest version:

sudo easy_install -U pip

Also make sure you have the lastest XCode installed (ver 4.4) with Command Line Tools.

Answered By: clwen

I changed the permissions for Python folder (from root to my user), and now everything work for me:

sudo chown -R <your_user>:wheel /Library/Python/2.7/site-packages/

Not recommended for machines with multiple users.

Answered By: Daniel Pérez Rada

I had a similar error except that sudo pip did not work either. I am using a “brew” installation of python (which is symlinked to /usr/local/bin) and found that the problem was that the shebangs in the pip and easy_install files were hardcoded to #!/usr/bin/python instead of #!/usr/local/bin/python, and so was using the system python version instead of the brew version.

Cheers,
Tom

Answered By: Tom Close

Rather than change ownership, it is possible to simply change permissions:

$ sudo chmod -R o+rX /Library/Python/2.7/site.packages

Answered By: Eric Mercer

I tried all the answers here, from reinstall easy_install to install a new python version, nothing worked for me.

What I did was install a fresh Python install in the /Library/Frameworks folder, and symlink to that one from /usr/local/bin (for some reason, my system had a symlink from /Library/Frameworks/Python.framework to /System/Frameworks/Python.framework). My idea was to keep the /System/Library/Frameworks files to be used by system commands in /usr/bin, and have /usr/local/bin points to another “user land” install in /Library/Frameworks. In order to do that :

  • rename /System/Library/Framework/Python.framework into _OLD_Python.framework

  • delete every python file in /usr/local/bin (using sudo rm /usr/local/bin/python*) and /usr/local/bin/pip* (but do NOT touch /usr/bin)

  • Reinstall python from the official site (http://www.python.org/getit/)
    ==> This will reinstall python in /Library/Framework and not /System/Library/Framework

  • Then launch the Applications/Python/Update Shell Profile.command command that will make sure your path is using that one

  • Then recreate the symlinks in /usr/local/bin using

    ln -s ../../Library/Frameworks/Python.framework/Versions/2.7/bin/python python

  • Finaly, rename the _OLD_Python.framework back to Python.framework (because that’s the path /usr/bin/python points to)

Typing “which python” should point to /Library/… and not /System/Library. From there you should be able to reinstall easy_install and pip properly.

Answered By: Ben G

I usually had same issue with some project referencing bonjour-py in their requirements.txt, didn’t know which or how to track that one at the moment.

And someone told me that pip-tool. It’s actually a great alternative to identify which you have, and if you want to update them. And as a bonus it ignored well the bonjour-py error.

Answered By: Brice

On Mavericks, I found that

ls -l `which python`
/usr/local/bin/python -> ../../../Library/Frameworks/Python.framework/Versions/2.7/bin/python

while pip showed

ls -l `which pip`
/usr/local/bin/pip

I renamed the old pip and created a symlink to the proper pip binary, and now all is well. It’s probably not the best solution, but it works.

Answered By: Sergio

I actually couldn’t do what was suggested. I instead had to execute:

xcode-select --install

Then I was able to install the ldap module.

Answered By: supreme Pooba

I fixed this by reinstalling python with homebrew: brew install python

Answered By: Jesse Aldridge

This works for me

rm -f /usr/local/bin/easy_install
brew reinstall python
pip install --upgrade setuptools
pip install --upgrade pip
Answered By: Thi
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.