macos 删除重复的python安装后,Python在mac上要求旧路径

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10212270/
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-10-21 09:06:03  来源:igfitidea点击:

Python asks for older paths on mac after deleting duplicate python installation

pythonmacospython-2.7virtualenv

提问by cgl

I am having the below error after a clean installation of python via brew install python. The link belongs to a previous python installation which I deleted manually.

通过 brew install python 全新安装 python 后,我遇到以下错误。该链接属于我手动删除的以前的 python 安装。

$ virtualenv ENV
python: posix_spawn: /System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: No such file or directory

I am using MacOS 10.7.3 and I installed virtualenv via pip:

我使用的是 MacOS 10.7.3,我通过 pip 安装了 virtualenv:

$ sudo /usr/local/share/python/pip install virtualenv
 Downloading/unpacking virtualenv
 Downloading virtualenv-1.7.1.2.tar.gz (2.1Mb): 2.1Mb downloaded
 Running setup.py egg_info for package virtualenv

 warning: no previously-included files matching '*.*' found under directory 'docs/_templates'
 Installing collected packages: virtualenv
 Running setup.py install for virtualenv

 warning: no previously-included files matching '*.*' found under directory 'docs/_templates'
 Installing virtualenv script to /usr/local/share/python
 Successfully installed virtualenv
 Cleaning up...
$ virtualenv ENV
 python: posix_spawn: /System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: No such file or directory

How can I fix this?

我怎样才能解决这个问题?

Edit : I reinstalled MacOSx and now returned back to my previous status that made me delete the preinstalled python.

编辑:我重新安装了 MacOSx,现在又回到了以前的状态,这让我删除了预装的 python。

$ which python 
/Library/Frameworks/Python.framework/Versions/2.7/bin/python 
$ which pip /usr/local/bin/pip $ sudo pip install virtualenv
Downloading/unpacking virtualenv 
Downloading virtualenv-1.7.1.2.tar.gz (2.1Mb): 2.1Mb downloaded
Running setup.py egg_info for package virtualenv

warning: no previously-included files matching '*.*' found under directory 'docs/_templates'
Installing collected packages: virtualenv
Running setup.py install for virtualenv

warning: no previously-included files matching '*.*' found under directory 'docs/_templates'
Installing virtualenv script to /usr/local/bin
Successfully installed virtualenv
Cleaning up...


$ python virtualenv.py ENV
/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/??MacOS/Python: can't open file 'virtualenv.py': [Errno 2] No such file or directory

The virtualenv.py is located at /Library/Python/2.7/site-packages/virtualenv.py and /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/py2app/recipes/virtualenv.py but somehow python misses all.

virtualenv.py 位于 /Library/Python/2.7/site-packages/virtualenv.py 和 /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/py2app/recipes/virtualenv.py但不知何故python错过了一切。

Why there is so much mess? How should I proceed to fix this?

为什么会有这么多乱七八糟的?我应该如何解决这个问题?

回答by andilabs

I had the very same situation after done stupid thing of deleting whole /System/Library/Frameworks/Python.framework/what results in error:

在完成删除整个/System/Library/Frameworks/Python.framework/导致错误的愚蠢事情后,我遇到了同样的情况:

python: posix_spawn: /System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: No such file or directory

python: posix_spawn: /System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: No such file or directory

I managed to restore it, because I had a earlier copy of my whole disk, and just by copy-pasting the whole Python.framework directory back.

我设法恢复了它,因为我有整个磁盘的早期副本,只需将整个 Python.framework 目录复制粘贴回来即可。

I don't know how much it is system dependent, but if somebody would like to try do that the same way instead of reinstalling whole OS X, the whole Python.framework zipped from me is here: http://andilabs.com/Python.framework.zip

我不知道它在多大程度上依赖于系统,但是如果有人想尝试以相同的方式而不是重新安装整个 OS X,那么从我这里压缩的整个 Python.framework 在这里:http://andilabs.com/ Python.framework.zip

回答by Ned Deily

It looks like you have deleted the Apple-supplied Python 2.7 that is part of OS X 10.7. That's a bad thing to do. You may have inadvertently broken parts of OS X that depend on it. In general, never delete anything in /usr(other than /usr/local) or in /System/Library. If you install a newer version of something, manage that via $PATH, not by deleting. The best long-term thing to do is reinstall what you've deleted; the safest way to do that is to reinstall OS X. A temporary workaround mightbe to move /usr/bin/pythonout of the way and replace it with a link to /usr/local/bin/python2.7but you really should undo the damage to your system.

看起来您已经删除了 Apple 提供的 Python 2.7,它是 OS X 10.7 的一部分。这是一件坏事。您可能无意中损坏了依赖它的 OS X 部分。通常,永远不要删除/usr(除了/usr/local)或 中的任何内容/System/Library。如果您安装了较新版本的东西,请通过 $PATH 进行管理,而不是删除。最好的长期做法是重新安装已删除的内容;最安全的方法是重新安装 OS X。一个临时的解决方法可能是移开/usr/bin/python并用链接替换它,/usr/local/bin/python2.7但您确实应该消除对系统的损坏。

UPDATE: Now that you've restored the system Python (good!), we can get at your original issue. Without more information, I can only speculate but chances are that you are installing virtualenvto the wrong Python instance. Keep in mind that you need to install a copy of Distribute(or its predecessor, setuptools), which provides the easy_installcommand, and a separate copy of pipin every instance of Python that you want to use. If you use the easy_installthat Apple ships with OS X, you will be installing to the Apple system Python. You mention using brewin a comment. If so, you should follow the instructions and recipes for it; that's why you have a package manager. But here's how you would install everything from scratch:

更新:现在您已经恢复了系统 Python(很好!),我们可以解决您的原始问题。没有更多信息,我只能推测,但很可能您安装 virtualenv到了错误的 Python 实例。请记住,您需要安装 的副本Distribute(或其前身setuptools),它提供easy_install命令,并pip在要使用的每个 Python 实例中安装的单独副本。如果您使用easy_installApple 随 OS X 提供的程序,您将安装到 Apple 系统 Python。您brew在评论中提到使用。如果是这样,您应该按照说明和食谱进行操作;这就是为什么你有一个包管理器。但这是从头开始安装所有内容的方法:

$ which python
/Library/Frameworks/Python.framework/Versions/2.7/bin/python
$ curl -O http://python-distribute.org/distribute_setup.py
$ python distribute_setup.py
[...]
creating /Library/Frameworks/Python.framework/Versions/2.7.3_release_10.6/lib/python2.7/site-packages/distribute-0.6.26-py2.7.egg
Extracting distribute-0.6.26-py2.7.egg to /Library/Frameworks/Python.framework/Versions/2.7.3_release_10.6/lib/python2.7/site-packages
Adding distribute 0.6.26 to easy-install.pth file
Installing easy_install script to /Library/Frameworks/Python.framework/Versions/2.7/bin
Installing easy_install-2.7 script to /Library/Frameworks/Python.framework/Versions/2.7/bin

Installed /Library/Frameworks/Python.framework/Versions/2.7.3_release_10.6/lib/python2.7/site-packages/distribute-0.6.26-py2.7.egg
Processing dependencies for distribute==0.6.26
Finished processing dependencies for distribute==0.6.26
After install bootstrap.
Creating /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg-info
Creating /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/setuptools.pth
$ curl -O https://raw.github.com/pypa/pip/master/contrib/get-pip.py
$ python get-pip.py
$ which pip
/Library/Frameworks/Python.framework/Versions/2.7/bin/pip
$ pip install virtualenv
[...]
    Installing virtualenv script to /Library/Frameworks/Python.framework/Versions/2.7/bin
Successfully installed virtualenv
Cleaning up...
$ which virtualenv
/Library/Frameworks/Python.framework/Versions/2.7/bin/virtualenv
$ virtualenv ENV
New python executable in ENV/bin/python
Installing setuptools............done.
Installing pip...............done.
$ source ENV/bin/activate
(ENV)$ which python
/Users/nad/ENV/bin/python
(ENV)$