Python v3.10.x - Table Output - ImportError: cannot import name 'Iterable' from 'collections'
See original GitHub issueDescribe the bug
-o table
output does not work as of Python v3.10.x.
Errors:
Table output unavailable. Use the --query option to specify an appropriate query. Use --debug for more info.
To Reproduce:
- Get an ARM template
- Run any command whatsoever with the
-o table
output format(I’ve been testing withaz deployment group validate [...] -o table
- Command runs fine, but returns a non-0 error, with the above-mentioned error message.
Afer running in --debug
mode, I found that the issue pertains to using Python 3.10.x specifically. It returns the following error, which I’ve seen referenced here and there in the AzureCLI Github issues, namely: https://github.com/Azure/azure-cli/issues/20444, meaning this fix has already been done, yet keeps coming back.
cli.knack.output: Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/knack/output.py", line 76, in format_table
return to.dump(result_list)
File "/usr/local/lib/python3.10/dist-packages/knack/output.py", line 207, in dump
from tabulate import tabulate
File "/usr/local/lib/python3.10/dist-packages/tabulate.py", line 7, in <module>
from collections import namedtuple, Iterable
ImportError: cannot import name 'Iterable' from 'collections' (/usr/lib/python3.10/collections/__init__.py)
cli.azure.cli.core.util: azure.cli.core.util.handle_exception is called with an exception:
cli.azure.cli.core.util: Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/knack/output.py", line 76, in format_table
return to.dump(result_list)
File "/usr/local/lib/python3.10/dist-packages/knack/output.py", line 207, in dump
from tabulate import tabulate
File "/usr/local/lib/python3.10/dist-packages/tabulate.py", line 7, in <module>
from collections import namedtuple, Iterable
ImportError: cannot import name 'Iterable' from 'collections' (/usr/lib/python3.10/collections/__init__.py)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/knack/cli.py", line 237, in invoke
self.output.out(cmd_result, formatter=formatter, out_file=out_file)
File "/usr/local/lib/python3.10/dist-packages/knack/output.py", line 146, in out
output = formatter(obj)
File "/usr/local/lib/python3.10/dist-packages/knack/output.py", line 79, in format_table
raise CLIError("Table output unavailable. "
knack.util.CLIError: Table output unavailable. Use the --query option to specify an appropriate query. Use --debug for more info.
Expected Behavior
Should return a table output.
Environment Summary
Linux-5.10.102.1-microsoft-standard-WSL2-x86_64-with-glibc2.35, Ubuntu 22.04 LTS
Python 3.10.4
Installer: PIP
azure-cli 2.37.0
Extensions:
azure-devops 0.25.0
aks-preview 0.5.79
Dependencies:
msal 1.18.0b1
azure-mgmt-resource 21.1.0b1
Additional Context
Issue Analytics
- State:
- Created a year ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
cannot import name 'Iterable' from 'collections' in Python
When searching for this error, it seems that Python 3.10 has compatibility issues which cause this error to appear; I saw it suggested...
Read more >ImportError: cannot import name Iterable from 'collections'
Trying to import the Iterable class from the collections module in Python versions 3.10+. Installing a module that imports the Iterable class from...
Read more >ImportError cannot import name Iterabler from collections ...
ImportError-cannot import name Iterabler from collections python 3-10. The Iterable abstract class was removed from collections in Python 3.10.
Read more >1926080 – packit fails to build with Python 3.10: ImportError
Bug 1926080 - packit fails to build with Python 3.10: ImportError: cannot import name 'Iterable' from 'collections'.
Read more >1718878 - Python 3.10 Support: Use `collections.abc` instead ...
It looks like the collections module was removed in python 3.10 after being deprecated since python 3.3. There is a new module called...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@jiasli The issue was indeed the
tabulate
package version. I had0.8.2
installed instead of0.8.10
. I ranpython3 -m pip install --upgrade tabulate
, which upgraded to0.8.10
, and now the-o table
argument works like a charm. Our Dockerfile also installs other Python packages, such asansible
,pywinrm
, etc., so I suppose that another package installed before AzureCLI most likely installedtabulate
with a hard-requirement of0.8.2
, and it didn’t get upgraded when AzureCLI was installed. I’ll troubleshoot this on my side to figure out which package, and if it running0.8.10
will cause an issue.Thanks for your help!
EDIT: If anyone ends up here looking at this same issue, in my case, turns out
ansible
was installing v0.8.2 oftabulate
. This is because we’re using an old version ofansible
, v2.9.27, due to us still mostly running on CentOS and thus not supporting newer versions. Older ansible versions rely on older versions of AzureCLI, in this case, v2.0.35, which itself has a requirement for a maxtabulate
version of v0.8.2, since newer versions didn’t exist at the time obviously.The
tabulate
issue was reported long ago (#20348) and was fixed by #20195.I can’t reproduce this error with above steps:
Could you run
python3 -m pip list -v
and check thetabulate
package version?If you want to use pip, creating a virtual environment first is recommended. See https://github.com/Azure/azure-cli/issues/20476.
Please also note that we recommend using the official Azure CLI DEB package to install. Please see https://github.com/Azure/azure-cli/issues/19640.