简体   繁体   English

在OS X 10.8升级后Python点破

[英]Python pip broken after OS X 10.8 upgrade

Made the upgrade to Mac OS X 10.8 (Mountain Lion) and get now the following error when trying to call $ pip : 升级到Mac OS X 10.8(Mountain Lion),并在尝试调用$ 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. 更新:尝试通过再次执行安装过程(使用http://www.pip-installer.org/en/latest/installing.html#using-the-installereasy_install )重新安装,但没有成功,同样的错误。

Tried now the following: Calling $ sudo pip and the above error disappears. 现在尝试以下操作:调用$ sudo pip ,以上错误消失。 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/..: 奇怪的是,在上述错误消息中找不到的目录指向/ System / Library / ...,而python安装是(new?),可以在/ Library / Frameworks / ..中找到:

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

Any idea how to get rid of the sudo? 知道如何摆脱sudo吗?

Use easy_install to update your pip to the latest version: 使用easy_install将您的pip更新为最新版本:

sudo easy_install -U pip

Also make sure you have the lastest XCode installed (ver 4.4) with Command Line Tools . 还要确保使用Command Line Tools安装了最新的XCode (4.4版)。

This works for me 这对我有用

rm -f /usr/local/bin/easy_install
brew reinstall python
pip install --upgrade setuptools
pip install --upgrade pip

I had a similar error except that sudo pip did not work either. 我有一个类似的错误,只是sudo pip也不起作用。 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. 我正在使用python的“酿造”安装程序(与/ usr / local / bin符号链接),发现问题是pip和easy_install文件中的shebang被硬编码为#!/usr/bin/python而不是#!/usr/local/bin/python ,因此使用的是系统python版本而不是brew版本。

Cheers, Tom 干杯汤姆

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. 然后,我能够安装ldap模块。

I tried all the answers here, from reinstall easy_install to install a new python version, nothing worked for me. 我在这里尝试了所有答案,从重新安装easy_install到安装新的python版本,对我没有任何帮助。

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). 我所做的是在/ Library / Frameworks文件夹中安装了一个全新的Python安装程序,并从/ usr / local / bin符号链接到该目录(出于某种原因,我的系统从/Library/Frameworks/Python.framework到/ 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. 我的想法是将/ System / Library / Frameworks文件保留在/ usr / bin中,以供系统命令使用,并且将/ usr / local / bin指向/ Library / Frameworks中安装的另一个“用户土地”。 In order to do that : 为了做到这一点:

  • rename /System/Library/Framework/Python.framework into _OLD_Python.framework 将/System/Library/Framework/Python.framework重命名为_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) 删除/ usr / local / bin中的每个python文件(使用sudo rm / usr / local / bin / python *)和/ usr / local / bin / pip *(但不要触摸/ 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 从官方站点( http://www.python.org/getit/ )重新安装python ==>这将在/ Library / Framework中而不是/ System / Library / Framework中重新安装python。

  • Then launch the Applications/Python/Update Shell Profile.command command that will make sure your path is using that one 然后启动Applications / Python / Update Shell Profile.command命令,以确保您的路径正在使用该命令

  • Then recreate the symlinks in /usr/local/bin using 然后使用以下命令在/ usr / local / bin中重新创建符号链接

    ln -s ../../Library/Frameworks/Python.framework/Versions/2.7/bin/python python 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) 最后,将_OLD_Python.framework重命名回Python.framework(因为这是/ usr / bin / python指向的路径)

Typing "which python" should point to /Library/... and not /System/Library. 输入“哪个python”应该指向/ Library / ...而不是/ System / Library。 From there you should be able to reinstall easy_install and pip properly. 从那里您应该能够重新安装easy_install并正确点子。

Rather than change ownership, it is possible to simply change permissions: 除了更改所有权之外,还可以简单地更改权限:

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

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. 我重命名了旧的pip并创建了一个指向正确pip二进制文件的符号链接,现在一切正常。 It's probably not the best solution, but it works. 这可能不是最好的解决方案,但它可以工作。

我通过使用自制软件重新安装python来解决此问题: brew install python

I changed the permissions for Python folder (from root to my user), and now everything work for me: 我更改了Python文件夹的权限(从root到我的用户),现在一切对我都有效:

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

Not recommended for machines with multiple users. 不建议用于具有多个用户的计算机。

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. 我通常对某些在他们的requirements.txt引用bonjour-py项目存在相同的问题,目前不知道该跟踪哪个或如何跟踪该项目。

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. 作为奖励,它很好地忽略了bonjour-py错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM