pip给出“importorror:没有名为setuptools的模块”,但是我可以在python interp中导入setuptools

2024-05-16 23:39:11 发布

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

我正在安装一个新的mac,我一直很好地哼唱着,安装pip和一些软件包。突然间,我试图运行的每一个pip命令都会抛出

Exception:
Traceback (most recent call last):
  File "/Library/Python/2.6/site-packages/pip-1.2.1-py2.6.egg/pip/basecommand.py", line 107, in main
    status = self.run(options, args)
  File "/Library/Python/2.6/site-packages/pip-1.2.1-py2.6.egg/pip/commands/install.py", line 248, in run
    import setuptools
ImportError: No module named setuptools

我想我无意中删除了一个目录或其他东西,所以我尝试按照这个站点上other answers的建议重新安装setuptools。我从here下载了setuptools egg,并像运行shell脚本一样运行它。得到这个输出:

Processing setuptools-0.6c11-py2.7.egg
Removing /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg
Copying setuptools-0.6c11-py2.7.egg to /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
setuptools 0.6c11 is already the active version in easy-install.pth
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/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg
Processing dependencies for setuptools==0.6c11
Finished processing dependencies for setuptools==0.6c11

现在,如果我启动一个交互式python会话,我可以import setuptools而不会出错,但是pip(和其他命令行脚本)抱怨它没有安装。你知道为什么Python似乎找到了它,但没有找到其他脚本吗?

如果有帮助,这就是sys.path中的内容:

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg
/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages

Tags: installpipin脚本eggmaclibpackages
1条回答
网友
1楼 · 发布于 2024-05-16 23:39:11

您的pip似乎与您的Python不一致。比较:

File "/Library/Python/2.6/site-packages/pip-1.2.1-py2.6.egg/pip/basecommand.py", line 107, in main

Installed /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg

如果python2.7有setuptools,那么您应该有

/Library/Frameworks/Python.framework/Versions/2.7/bin/easy_install-2.7

可用,在这种情况下

easy_install-2.7 pip

应该给你pip-2.7

相关问题 更多 >