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'
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 doctor
did 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:
sudo chown -R $(whoami) $(brew --prefix)/*
pyenv install 3.6.4
High Sierra (10.13.4) made me do it.
My solution to MacOS Mojave (10.14.2):
mkdir -p /usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages
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:
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/*
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.
Ran again the brew doctor
, This time it showed me no issues.
Your system is ready to brew.
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
Most helpful comment
My solution to MacOS Mojave (10.14.2):
mkdir -p /usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages
curl https://bootstrap.pypa.io/ez_setup.py | python3
Thank @julielerman for the earlier solution.