0

I'm trying to run azure CLI after reinstalling it I'm getting:

$ 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.

I checked the python binary path and I saw I already have this package.

1 Answers1

1

Found the issue. One of the sub-packages that called in the pyparsing package was called to a local folder script that has the same name. and as a result the import faild.

$ /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'

So pyparsing imports copy and I had copy.py in my path. after rename the script it worked

  • You are not the first one this has happened to, and won't be the last. It is easy to run afoul of Python imports if you accidentally choose a name that is the same as some library from the stdlib, or from some embedded lib. It is surprising that this doesn't happen more often. I'm glad you were able to sort it out. – PaulMcG Jul 08 '21 at 19:44