删除某些内容后如何在 OS X Yosemite 上恢复 python? [英] How to restore python on OS X Yosemite after I've deleted something?
问题描述
我想我以前通过自制软件安装了python.这不是一个好主意,但我做到了:
$ which python/Library/Frameworks/Python.framework/Versions/2.7/bin/python$ sudo rm -R/Library/Frameworks/Python.framework/Versions/2.7/bin/python
...然后终端告诉我...
$ which python/usr/local/bin/python
但是当我再次运行python时
$ python-bash:/Library/Frameworks/Python.framework/Versions/2.7/bin/python: 没有那个文件或目录
所以我这样做了:
export PATH=/usr/local/bin:/usr/local/sbin:$PATH
现在 python 确实在我的终端上运行,但我想知道是否最好将某些东西放回我删除它的地方,以及我如何恢复"python 在我弄乱它之前?
谢谢!
这里有很多问题.
让我们从这个开始:
/Library/Frameworks/Python/2.7
既不是 Apple Python,也不是 Homebrew Python.您显然安装了第三个 Python,可能是来自官方 python.org 二进制安装程序的那个.删除那个不会影响 Homebrew 的那个.
/usr/local/bin/python
也不是 Apple Python.它可能是你的第三个 Python 或 Homebrew Python 的符号链接,但它不是来自 Apple.
这是每个 Python 的去向:
Apple 的 Python 位于
/System/Library/Frameworks/Python/2.7
.它还包括/usr/bin
中的各种包装器可执行文件,包括/usr/bin/python
,指向/System
框架.您使用该 Python 安装的任何额外内容(例如,通过easy_install
或pip
)包括可执行文件或脚本都将进入/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
>.
因此,您试图通过确保 /usr/local/bin
在您的 PATH 上来回到 Apple Python 的事实已经朝着错误的方向前进.
与此同时,除非 brew doctor
告诉你,否则不要手动删除 Homebrew 安装的东西.只需使用 brew uninstall python
— 或者,如果您想暂时将其移开,并选择稍后恢复,请使用 brew unlink python
.
最后,即使在更改了 PATH
之后,shell 可能已经缓存了查找 python
的最佳位置,因此要么读取 hash
> 命令,或者,如果您不想了解有关 bash 的更多信息,只需确保打开一个新 shell(例如,通过在 Terminal.app 中打开一个新选项卡).
无论如何,你如何回到原来的位置?
您需要彻底卸载两个额外的 Python.我已经解释了如何使用上面的 Homebrew 来做到这一点.对于第三个,您已经完成了大部分工作,但是在 /usr/local/bin
中显然还有一些东西.如果它们都是悬空的符号链接,这似乎很可能,你可以很容易地找到它们,例如, ls -l/usr/local/bin |grep/Library/Frameworks/Python.framework |grep -v/系统
.
完成后,只需启动一个新的 shell,which python
应该告诉你 /usr/bin/python
,一切都会再次快乐.>
I think I previously installed python through homebrew. It was not a good idea but I did:
$ 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
-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?
Thanks!
You've got a multitude of problems here.
Let's start off with this:
/Library/Frameworks/Python/2.7
is neither the Apple Python nor the Homebrew Python. You apparently installed a third Python, maybe the one from the official python.org binary installers. Removing that one won't affect the Homebrew one.
/usr/local/bin/python
is 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.
Here's where each Python goes:
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/System
framework. Any extra stuff you install with that Python (e.g., viaeasy_install
orpip
) 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'sbin
directory 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
.
So, the fact that you're trying to get back to the Apple Python by making sure /usr/local/bin
is on your PATH is already heading in the wrong direction.
Meanwhile, never manually delete something installed by Homebrew unless brew doctor
tells 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
.
Finally, even after changing your PATH
, the shell may have cached the best location to find python
, so either read up on the hash
command 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).
Anyway, how do you get back to where you were?
You need to cleanly uninstall both extra 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
.
Having done that, just fire up a new shell, and which python
should tell you /usr/bin/python
, and everything will be happy again.
这篇关于删除某些内容后如何在 OS X Yosemite 上恢复 python?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!