【发布时间】:2018-05-20 21:04:56
【问题描述】:
我正在使用 macOS High Sierra。在过去的某个时候,我通过 brew 安装了 Python,但是由于某种原因(我不知道)pip 无法工作:
$ pip --version Traceback (most recent call last):
File "/usr/local/opt/python2/libexec/bin/pip", line 6, in <module>
from pkg_resources import load_entry_point
File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 3195, in <module>
@_call_aside
File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 3179, in _call_aside
f(*args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 3208, in _initialize_master_working_set
working_set = WorkingSet._build_master()
File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 683, in _build_master
return cls._build_from_requirements(__requires__)
File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 696, in _build_from_requirements
dists = ws.resolve(reqs, Environment())
File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 885, in resolve
raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'pip==9.0.1' distribution was not found and is required by the application
因此我发出:
$ brew uninstall python@2
Uninstalling /usr/local/Cellar/python@2/2.7.14_1... (3,622 files, 50.6MB)
在这之后,我假设是 python 的默认安装
$ which python
/usr/bin/python
很遗憾,我无法通过键入 python 来运行 Python:
$ python --version
-bash: /usr/local/opt/python2/libexec/bin/python: No such file or directory
但是我可以通过直接引用它来运行那个 python 解释器:
$ /usr/bin/python --version
Python 2.7.10
python --version 不起作用,这让我很困扰,我想知道这是否是以前在此处安装了 brew 安装的 python 版本的结果。于是我决定用brew install python@2重新安装,成功了。
python的假设位置已经改变:
$ which python
/usr/local/bin/python
但是当我尝试使用它时仍然遇到同样的错误:
$ python --version
-bash: /usr/local/opt/python2/libexec/bin/python: No such file or directory
当然,使用 python 解释器的完整路径可以正常工作:
$ /usr/local/bin/python --version
Python 2.7.15
任何人都可以帮我诊断为什么即使 which python 声明 python 位于 /usr/local/bin/python,但简单地发出 python 会失败并显示 /usr/local/opt/python2/libexec/bin/python: No such file or directory?? p>
编辑:响应者要求运行file 的输出,这是输出:
$ file /usr/bin/python
/usr/bin/python: Mach-O universal binary with 2 architectures: [i386:Mach-O executable i386] [x86_64:Mach-O 64-bit executable x86_64]
/usr/bin/python (for architecture i386): Mach-O executable i386
/usr/bin/python (for architecture x86_64): Mach-O 64-bit executable x86_64
$ file /usr/local/bin/python
/usr/local/bin/python: Mach-O 64-bit executable x86_64
编辑:响应者要求输出brew doctor。这是输出:
Warning: Putting non-prefixed coreutils in your path can cause gmp builds to fail.
Warning: Unbrewed header files were found in /usr/local/include.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.
Warning: Broken symlinks were found. Remove them with `brew prune`:
/usr/local/bin/apm
/usr/local/bin/atom
编辑:PATH 的输出,有趣的是 /usr/local/opt/python2/libexec/bin 在那里
$ echo $PATH
/usr/local/opt/coreutils/libexec/gnubin:/Applications/google-cloud-sdk/bin:/usr/local/opt/python2/libexec/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/share/dotnet:/Applications/Wireshark.app/Contents/MacOS
$ ls /usr/local/opt/python2/libexec/bin
ls: cannot access '/usr/local/opt/python2/libexec/bin': No such file or directory
$ ls /usr/local/opt/python2/libexec
pip setuptools wheel
【问题讨论】:
-
请检查
/usr/bin/python和file /usr/bin/python;输出是什么? -
@AnttiHaapala 感谢您的回复。我用该信息更新了问题。
-
好吧,我不会假装我知道这里发生了什么:D
-
没关系。您提示我提供其他可能有用的信息。
-
brew doctor的输出是什么?