Azure-cli: az --version returns pkg_resources error

Created on 10 Mar 2018  Â·  7Comments  Â·  Source: Azure/azure-cli

Environment summary

Runtime Environment:
OS Name: Mac OS X
OS Version: 10.13
OS Platform: Darwin
RID: osx.10.12-x64

Installed via brew

az --version
returns:

➜  ~ az --version 
No module named 'pkg_resources'
Traceback (most recent call last):
  File "/usr/local/Cellar/azure-cli/2.0.28_2/libexec/lib/python3.6/site-packages/knack/cli.py", line 187, in invoke
    self.show_version()
  File "/usr/local/Cellar/azure-cli/2.0.28_2/libexec/lib/python3.6/site-packages/azure/cli/core/__init__.py", line 79, in show_version
    print(get_az_version_string())
  File "/usr/local/Cellar/azure-cli/2.0.28_2/libexec/lib/python3.6/site-packages/azure/cli/core/util.py", line 60, in get_az_version_string
    installed_dists = get_installed_cli_distributions()
  File "/usr/local/Cellar/azure-cli/2.0.28_2/libexec/lib/python3.6/site-packages/azure/cli/core/util.py", line 51, in get_installed_cli_distributions
    from pkg_resources import working_set
ModuleNotFoundError: No module named 'pkg_resources'

Most helpful comment

My solution to MacOS Mojave (10.14.2):

  • Create folder mkdir -p /usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages
  • Run curl https://bootstrap.pypa.io/ez_setup.py | python3

Thank @julielerman for the earlier solution.

All 7 comments

Run brew doctor to check your Python installation.
pkg_resources is a Python core module so if that's not working, check your Python installation.

thanks. brew doctordid have me try to link python again but that was throwing an error re permissions. That took a few other "fixes" but I finally succeeded with the link yet az --version still failed. Finally found this stackoverflow (https://stackoverflow.com/questions/7446187/no-module-named-pkg-resources) that led me to using this command:
curl https://bootstrap.pypa.io/ez_setup.py | python
which still didn't work until I created a site-packages folder deep in
/usr/local/Cellar/python/3.6.4_3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/
So the tail chasing took some time but I finally have it working.
Thanks

Another way to tackle, brew, az, python here and python there:

  • Uninstalling all brew python versions
  • opening up the brew install dir sudo chown -R $(whoami) $(brew --prefix)/*
  • running brew doctor and re-linking all poor, unlinked packages
  • Installing pyenv with brew
  • Making the necessary PATH modifications.
  • Python again pyenv install 3.6.4

High Sierra (10.13.4) made me do it.

My solution to MacOS Mojave (10.14.2):

  • Create folder mkdir -p /usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages
  • Run curl https://bootstrap.pypa.io/ez_setup.py | python3

Thank @julielerman for the earlier solution.

In my case, I've simply ran brew reinstall python followed by pip3 install setuptools and it worked. Using MacOS Mojave here.

I had the same issue on macOS 10.14.3. Fixed it this way:

  1. Ran the command brew doctor, which showed me this.
Warning: The following directories do not exist:
/usr/local/sbin

You should create these directories and change their ownership to your account.
  sudo mkdir -p /usr/local/sbin
  sudo chown -R $(whoami) /usr/local/sbin

Warning: Broken symlinks were found. Remove them with `brew cleanup`:
  /usr/local/share/man/man3/*
  1. I did the commands sudo mkdir -p /usr/local/sbin and sudo chown -R $(whoami) /usr/local/sbin, then brew cleanup, as brew suggested above.

  2. Ran again the brew doctor, This time it showed me no issues.

Your system is ready to brew.
  1. The last step was this command brew reinstall python3.

After the above steps the command az started working fine.

This fixed it for me:
sudo mkdir /usr/local/Frameworks
sudo chown -R $(whoami) /usr/local/Frameworks
brew reinstall python

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dhermans picture dhermans  Â·  3Comments

Kannaj picture Kannaj  Â·  3Comments

derekbekoe picture derekbekoe  Â·  3Comments

derekperkins picture derekperkins  Â·  3Comments

williexu picture williexu  Â·  3Comments