繁体   English   中英

“/lib/python2.7/site-packages/不支持.pth文件”在MacOS上安装pip

[英]“/lib/python2.7/site-packages/ does NOT support .pth files” installing pip on MacOS

我在我的mac上使用pip遇到了一些问题,并完全卸载了它。

现在当我尝试重新安装它时,运行$sudo easy_install pip我得到:

TEST FAILED: /lib/python2.7/site-packages/ does NOT support .pth files
error: bad install directory or PYTHONPATH

You are attempting to install a package to a directory that is not
on PYTHONPATH and which Python does not read ".pth" files from.  The
installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:

    /lib/python2.7/site-packages/

and your PYTHONPATH environment variable currently contains:

    ''

[此粘贴输出因简洁而缩短]


我尝试使用./profile和./bash_profile将列出的目录(/lib/python2.7/site-packages/)添加到我的pythonpath中,但是当我运行python时它既不会影响sys.path变量,只包括

/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload
/Library/Python/2.7/site-packages
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC

我的问题是我安装了两个版本的python(在列出的两个目录下)?

或者是我的pythonpath被搞砸了,我一直无法弥补?


编辑:

$ which python返回/usr/bin/python

$ which easy_install返回/usr/bin/easy_install

我想到了。

当我尝试通过brew安装python2,然后运行brew doctor我收到了以下警告。

Warning: A .pydistutils.cfg file was found in $HOME, which may cause Python
builds to fail. See:
  https://bugs.python.org/issue6138
  https://bugs.python.org/issue4655

果然,当我删除.pydistutils.cfg时,问题就解决了。


FWIW,这是让我创建文件的SO问题:

将--user与--prefix错误与setup.py install结合使用

(答案确实提到它可能会导致意想不到的后果。我只是认为链接到它可能有助于搜索当前遇到同样问题的人的可见性,但忘记了他们创建了该文件。)

虽然我没有确切的答案,但我可以为你填写一些空白。

您的sys.path没有显示安装的两个版本的Python,它显示了一个根据Apple安装Python 2的奇怪方式安装的版本。

/System/Library/Frameworks/Python.framework/Versions/2.7/下的目录是Python的库和模块。 由于/System/Library/目录在Mac上是“受保护的”,因此它们无法使用SIP激活而写入,因此Apple提供目录/Library/Python/2.7/site-packages ,这是安装Python包(如pip地方。

在我的系统上, sudo /usr/bin/easy_install pip安装到/Library/Python/2.7/site-packages/

由于你的pip没有运行下一步,我建议你看看你是否可以从标准库中引导它sudo python -m ensurepip --default-pip 如果这不起作用,您可以找到有关如何在此处运行它的说明。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM