【问题标题】:"/lib/python2.7/site-packages/ does NOT support .pth files" installing pip on MacOS“/lib/python2.7/site-packages/ 不支持 .pth 文件”在 MacOS 上安装 pip
【发布时间】:2018-10-10 02:34:21
【问题描述】:

我在我的 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

【问题讨论】:

  • 能否添加which python和which easy_install的输出?
  • 当然,我编辑了它。
  • 好的,这并没有透露任何信息。你是如何卸载pip的?您运行的是哪个版本的 macOS?它安装了什么版本的python?
  • 我看到您发布了一个解决方案(删除~/.pydistutils.cfg)然后将其删除。查看消息来源表明这确实是原因。到底是失败了还是怎么的?
  • 当时不确定这是否成功了,或者是否与其他问题有关。我已取消删除它。

标签: python macos pip easy-install


【解决方案1】:

我想通了。

当我尝试通过 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 问题:

Combine --user with --prefix error with setup.py install

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

【讨论】:

  • 这解决了我的 virtualenv 问题。我花了几个小时到处寻找解决方案。谢谢!
  • 谢谢,这解决了我遇到的同样问题
【解决方案2】:

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

您的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 引导它。如果这不起作用,您可以找到有关如何使其运行的说明here。

【讨论】:

    猜你喜欢
    • 2017-09-02
    • 1970-01-01
    • 2021-05-07
    • 2017-04-25
    • 1970-01-01
    • 1970-01-01
    • 2016-03-28
    • 2021-01-02
    • 1970-01-01
    相关资源
    最近更新 更多