11

通过 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

我使用的是 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

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

编辑:我重新安装了 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

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 错过了所有。

为什么会有这么多混乱?我应该如何着手解决这个问题?

4

2 回答 2

17

/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.framework 目录复制粘贴回来。

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

于 2013-08-07T09:10:14.453 回答
8

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

更新:现在您已经恢复了系统 Python(很好!),我们可以解决您的原始问题。如果没有更多信息,我只能推测,但很可能您正在安装 virtualenv到错误的 Python 实例。请记住,您需要安装提供命令的副本Distribute(或其前身setuptools),并在您要使用的每个 Python 实例中安装easy_install一个单独的副本。pip如果您使用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)$  
于 2012-04-18T16:24:09.697 回答