删除某些内容后如何在 OS X Yosemite 上恢复 python?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26917765/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 01:09:49  来源:igfitidea点击:

How to restore python on OS X Yosemite after I've deleted something?

pythonterminal

提问by ngc

I think I previously installed python through homebrew. It was not a good idea but I did:

我想我以前通过自制软件安装了python。这不是一个好主意,但我做到了:

$ which python
/Library/Frameworks/Python.framework/Versions/2.7/bin/python
$ sudo rm -R /Library/Frameworks/Python.framework/Versions/2.7/bin/python

.. and then the terminal told me...

..然后终端告诉我......

$ which python
/usr/local/bin/python

But when I run python again

但是当我再次运行 python 时

$ python
-bash: /Library/Frameworks/Python.framework/Versions/2.7/bin/python: No such file or directory

So I did this:

所以我这样做了:

export PATH=/usr/local/bin:/usr/local/sbin:$PATH

Now python does run on my terminal but I was wondering if it would be better to put something back where I deleted it, and how I could "restore" however python was before I messed with it?

现在 python 确实在我的终端上运行,但我想知道是否最好将某些东西放回我删除它的地方,以及我如何“恢复”但是 python 在我弄乱它之前?

Thanks!

谢谢!

采纳答案by abarnert

You've got a multitude of problems here.

你这里有很多问题。

Let's start off with this:

让我们从这个开始:

/Library/Frameworks/Python/2.7is neither the Apple Python nor the Homebrew Python. You apparently installed a thirdPython, maybe the one from the official python.org binary installers. Removing that one won't affect the Homebrew one.

/Library/Frameworks/Python/2.7既不是 Apple Python 也不是 Homebrew Python。您显然安装了第三个Python,可能是来自官方 python.org 二进制安装程序的那个。删除那个不会影响 Homebrew 的。

/usr/local/bin/pythonis not the Apple Python either. It may be a symlink to your third Python or to the Homebrew Python, but it's not from Apple.

/usr/local/bin/python也不是 Apple Python。它可能是你的第三个 Python 或 Homebrew Python 的符号链接,但它不是来自 Apple。

Here's where each Python goes:

这是每个 Python 的去向:

  • Apple's Python is in /System/Library/Frameworks/Python/2.7. It also includes various wrapper executables in /usr/bin, including /usr/bin/python, that point at the /Systemframework. Any extra stuff you install with that Python (e.g., via easy_installor pip) that includes executables or scripts will go into /usr/local/bin, not /usr/bin, but Apple's pre-installed stuff never does.

  • Most third-party binary installers install into /Library/Frameworks/Python/2.7. Different versions can optionally add the framework's bindirectory to your path, or symlink the binaries into /usr/local/bin.

  • Homebrew installs to somewhere like /usr/local/Cellar/python/2.7.8, then symlinks various executables and scripts into /usr/local/bin.

  • Apple 的 Python 在/System/Library/Frameworks/Python/2.7. 它还包括 中的各种包装器可执行文件/usr/bin,包括/usr/bin/python,指向/System框架。您使用该 Python 安装的任何额外内容(例如,通过easy_installpip)包括可执行文件或脚本都将进入/usr/local/bin,而不是/usr/bin,但 Apple 的预安装内容永远不会。

  • 大多数第三方二进制安装程序安装到/Library/Frameworks/Python/2.7. 不同的版本可以选择将框架的bin目录添加到您的路径中,或者将二进制文件符号链接到/usr/local/bin.

  • Homebrew 安装到类似的地方/usr/local/Cellar/python/2.7.8,然后将各种可执行文件和脚本符号链接到/usr/local/bin.

So, the fact that you're trying to get back to the Apple Python by making sure /usr/local/binis on your PATH is already heading in the wrong direction.

因此,您试图通过确保/usr/local/bin在您的 PATH 上来回到 Apple Python 的事实已经朝着错误的方向前进。



Meanwhile, never manually delete something installed by Homebrew unless brew doctortells you to. Just use brew uninstall python—or, if you want to move it out of the way temporarily, with the option of restoring it later, brew unlink python.

同时,除非brew doctor告诉你,否则永远不要手动删除 Homebrew 安装的东西。只需使用brew uninstall python- 或者,如果您想暂时将其移开,并且可以选择稍后恢复,请使用brew unlink python.



Finally, even after changing your PATH, the shell may have cached the best location to find python, so either read up on the hashcommand or, if you don't want to learn more about bash, just make sure to open a new shell (e.g., by opening a new tab in Terminal.app).

最后,甚至改变你的后PATH,外壳可能已经缓存的最佳位置找到python,所以无论是阅读了关于该hash命令,或者,如果你不想了解庆典,只要确保打开一个新的外壳(例如,通过在 Terminal.app 中打开一个新选项卡)。



Anyway, how do you get back to where you were?

无论如何,你如何回到你原来的地方?

You need to cleanly uninstall bothextra Pythons. I already explained how to do that with the Homebrew one above. For the third one, you've done most of it, but there are apparently things left behind in /usr/local/bin. If they're all dangling symlinks, as seems most likely, you can find them pretty easily with, e.g., ls -l /usr/local/bin |grep /Library/Frameworks/Python.framework |grep -v /System.

您需要彻底卸载两个额外的 Python。我已经解释了如何使用上面的 Homebrew 来做到这一点。对于第三个,您已经完成了大部分工作,但/usr/local/bin. 如果它们都是悬空的符号链接,看起来很可能,你可以很容易地找到它们,例如,ls -l /usr/local/bin |grep /Library/Frameworks/Python.framework |grep -v /System.

Having done that, just fire up a new shell, and which pythonshould tell you /usr/bin/python, and everything will be happy again.

完成后,只需启动一个新的外壳,并且which python应该告诉您/usr/bin/python,一切都会再次快乐。