我尝试在重新安装 azure CLI 后运行它:
$ az
Traceback (most recent call last):
File "/usr/local/Cellar/python@3.8/3.8.11/Frameworks/Python.framework/Versions/3.8/lib/python3.8/runpy.py", line 185, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
File "/usr/local/Cellar/python@3.8/3.8.11/Frameworks/Python.framework/Versions/3.8/lib/python3.8/runpy.py", line 111, in _get_module_details
__import__(pkg_name)
File "/usr/local/Cellar/azure-cli/2.25.0/libexec/lib/python3.8/site-packages/azure/__init__.py", line 1, in <module>
__import__('pkg_resources').declare_namespace(__name__)
File "/usr/local/Cellar/azure-cli/2.25.0/libexec/lib/python3.8/site-packages/pkg_resources/__init__.py", line 78, in <module>
__import__('pkg_resources.extern.packaging.requirements')
File "/usr/local/Cellar/azure-cli/2.25.0/libexec/lib/python3.8/site-packages/pkg_resources/_vendor/packaging/requirements.py", line 9, in <module>
from pkg_resources.extern.pyparsing import stringStart, stringEnd, originalTextFor, ParseException
File "/usr/local/Cellar/azure-cli/2.25.0/libexec/lib/python3.8/site-packages/pkg_resources/extern/__init__.py", line 52, in create_module
return self.load_module(spec.name)
File "/usr/local/Cellar/azure-cli/2.25.0/libexec/lib/python3.8/site-packages/pkg_resources/extern/__init__.py", line 44, in load_module
raise ImportError(
ImportError: The 'pyparsing' package is required; normally this is bundled with this package so if you get this warning, consult the packager of your distribution.
我检查了 python 二进制路径,我看到我已经有了这个包。
答案 0 :(得分:1)
发现问题。 pyparsing 包中调用的子包之一被调用到具有相同名称的本地文件夹脚本。结果导入失败。
$ /usr/local/Cellar/azure-cli/2.25.0/libexec/bin/python
Python 3.8.11 (default, Jun 29 2021, 03:08:07)
[Clang 12.0.5 (clang-1205.0.22.9)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyparsing
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/Cellar/azure-cli/2.25.0/libexec/lib/python3.8/site-packages/pyparsing.py", line 104, in <module>
import copy
File "/Users/shprayev/copy.py", line 4, in <module>
from pymongo import MongoClient
ModuleNotFoundError: No module named 'pymongo'
所以 pyparsing 导入 copy 并且我的路径中有 copy.py。 重命名它工作的脚本后