Python pip broken after OS X 10.8 upgrade

2019-01-21 05:25发布

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?

标签: python macos pip
10条回答
Explosion°爆炸
2楼-- · 2019-01-21 06:01

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.

查看更多
Root(大扎)
3楼-- · 2019-01-21 06:07

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.

查看更多
Explosion°爆炸
4楼-- · 2019-01-21 06:08

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

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

查看更多
三岁会撩人
5楼-- · 2019-01-21 06:09

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

查看更多
登录 后发表回答