gpt4 book ai didi

python - macOS 上的 python 安装错误。我该如何修复?

转载 作者:行者123 更新时间:2023-12-01 09:25:29 26 4
gpt4 key购买 nike

我使用的是 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

任何人都可以帮我诊断为什么简单地发出 python 会失败并显示 /usr/local/opt/python2/libexec/bin/python: No such file or directory 即使 which python 声明 python 位于 /usr/local/bin/python

编辑:响应者询问运行文件的输出,这是输出:

$ 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

最佳答案

解决方案可能只是从 PATH 环境变量中删除 /usr/local/opt/python2/libexec/bin

为此,您必须编辑 ~/.bash_profile 并删除该目录的出现。

关于python - macOS 上的 python 安装错误。我该如何修复?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50439358/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com