azure-cli: cannot import name 'Iterable' from 'collections'

Describe the bug

Command Name az aks get-credentials

Errors:

The command failed with an unexpected error. Here is the traceback:
cannot import name 'Iterable' from 'collections' (/usr/local/Cellar/python@3.10/3.10.0_2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/collections/__init__.py)
Traceback (most recent call last):
  File "/usr/local/Cellar/azure-cli/2.30.0_1/libexec/lib/python3.10/site-packages/knack/cli.py", line 231, in invoke
    cmd_result = self.invocation.execute(args)
  File "/usr/local/Cellar/azure-cli/2.30.0_1/libexec/lib/python3.10/site-packages/azure/cli/core/commands/__init__.py", line 556, in execute
    self.commands_loader.load_arguments(command)
  File "/usr/local/Cellar/azure-cli/2.30.0_1/libexec/lib/python3.10/site-packages/azure/cli/core/__init__.py", line 517, in load_arguments
    self.command_table[command].load_arguments()  # this loads the arguments via reflection
  File "/usr/local/Cellar/azure-cli/2.30.0_1/libexec/lib/python3.10/site-packages/azure/cli/core/commands/__init__.py", line 313, in load_arguments
    super(AzCliCommand, self).load_arguments()
  File "/usr/local/Cellar/azure-cli/2.30.0_1/libexec/lib/python3.10/site-packages/knack/commands.py", line 104, in load_arguments
    cmd_args = self.arguments_loader()
  File "/usr/local/Cellar/azure-cli/2.30.0_1/libexec/lib/python3.10/site-packages/azure/cli/core/commands/command_operation.py", line 125, in arguments_loader
    op = self.get_op_handler(self.op_path)
  File "/usr/local/Cellar/azure-cli/2.30.0_1/libexec/lib/python3.10/site-packages/azure/cli/core/commands/command_operation.py", line 59, in get_op_handler
    handler = import_module(mod_to_import)
  File "/usr/local/Cellar/python@3.10/3.10.0_2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/Users/fed/.azure/cliextensions/aks-preview/azext_aks_preview/custom.py", line 41, in <module>
    from tabulate import tabulate  # pylint: disable=import-error
  File "/usr/local/Cellar/azure-cli/2.30.0_1/libexec/lib/python3.10/site-packages/tabulate.py", line 16, in <module>
    from collections import Iterable
ImportError: cannot import name 'Iterable' from 'collections' (/usr/local/Cellar/python@3.10/3.10.0_2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/collections/__init__.py)

To Reproduce:

  • az aks get-credentials --resource-group {} --name {} --subscription {} --admin

Expected Behavior

Environment Summary

macOS-11.6-x86_64-i386-64bit, Darwin 20.6.0
Python 3.10.0
Installer: HOMEBREW

azure-cli 2.30.0

Extensions:
front-door 1.0.9
aks-preview 0.4.65

Additional Context

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 4
  • Comments: 15 (3 by maintainers)

Most upvoted comments

The issue is with the Python version (>3.9)… Python realigned the modules.

  1. either use Python v3.9 or prior ones OR
  2. The base package needs to be modified (from where this import error is generating)
try:
    # Python <= 3.9
    from collections import Iterable
except ImportError:
    # Python > 3.9
    from collections.abc import Iterable

@XBeg9 Try rm -rf ~/.azure and running az login again. After doing this, I was able to run az get-credentials --resource-group {} --name {} --context {} successfully to connect via kubectl.

Annoyingly I can’t remember the other commands that I was seeing errors with to try them out to see if it resolves the issue. But there is a possibility it fixes the issue as now when I run az aks get-credentials I get the expected the following arguments are required .... as opposed to the above mentioned stacktrace.

Thanks @miwithro, I have tried this already.

I have tried just simply uninstalling and re-installing as well as uninstalling, running brew cleanup -s and even removing the brew cache directory rm -rf $(brew --cache) before re-installing again still yields the same results

Thank you so much for your solution! I was able to run the command!

Thanks @miwithro, I have tried this already.

I have tried just simply uninstalling and re-installing as well as uninstalling, running brew cleanup -s and even removing the brew cache directory rm -rf $(brew --cache) before re-installing again still yields the same results