删除重复的Python安装后,Python会在mac上请求较旧的路径

2024-03-29 11:42:27 发布

您现在位置:Python中文网/ 问答频道 /正文

在通过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却忽略了所有这些。

为什么这么乱?我该如何着手解决这个问题?


Tags: installpippyvirtualenvusrlocallibrarymacos
2条回答

我做了删除整个/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目录。

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

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

更新:现在您已经恢复了系统Python(很好!),我们可以查到你的原始版本。如果没有更多的信息,我只能推测,但可能是您将virtualenv安装到了错误的Python实例。请记住,需要在要使用的每个Python实例中安装提供easy_install命令的Distribute(或其前身setuptools)的副本,以及pip的单独副本。如果您使用苹果随OSX附带的easy_install,那么您将安装到苹果系统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)$  

相关问题 更多 >