我通过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错过了所有。
为什么会有这么多混乱?我该如何解决这个问题?
答案 0 :(得分:16)
在完成删除整个/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
答案 1 :(得分:7)
看起来你已经删除了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
的链接替换它,但你真的应该撤消对系统的损害。
更新:现在您已经恢复了系统Python(好!),我们可以解决您的原始问题。没有更多信息,我只能推测,但你可能正在将virtualenv
安装到错误的Python实例上。请注意,您需要安装Distribute
(或其前身setuptools
)的副本,该副本提供easy_install
命令,并在每个副本中安装pip
的单独副本您要使用的Python实例。如果您使用Apple随OS X提供的easy_install
,您将安装到Apple系统Python。您提到在评论中使用brew
。如果是这样,您应该关注the instructions and recipes for it;这就是为什么你有一个包经理。但是这里是你如何从头开始安装所有东西:
$ 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)$