python - “/lib/python2.7/site-packages/ 不支持 .pth 文件”在 MacOS 上安装 pip
问题描述
我在我的 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 结合使用
(那里的答案确实提到它可能会导致意想不到的后果。我只是认为链接到它可能有助于搜索当前遇到与我相同的问题但忘记了他们创建该文件的任何人的可见性。)