question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Python v3.10.x - Table Output - ImportError: cannot import name 'Iterable' from 'collections'

See original GitHub issue

Describe 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 with az 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:closed
  • Created a year ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
alexpilon666commented, Jun 22, 2022

@jiasli The issue was indeed the tabulate package version. I had 0.8.2 installed instead of 0.8.10. I ran python3 -m pip install --upgrade tabulate, which upgraded to 0.8.10, and now the -o table argument works like a charm. Our Dockerfile also installs other Python packages, such as ansible, pywinrm, etc., so I suppose that another package installed before AzureCLI most likely installed tabulate with a hard-requirement of 0.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 running 0.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 of tabulate. This is because we’re using an old version of ansible, 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 max tabulate version of v0.8.2, since newer versions didn’t exist at the time obviously.

0reactions
jiaslicommented, Jun 22, 2022

The tabulate issue was reported long ago (#20348) and was fixed by #20195.

I can’t reproduce this error with above steps:

# apt update && apt upgrade -y && apt install -y python3-pip
# python3 -m pip install azure-cli==2.37.0

# python3 -m pip list -v
...
azure-cli                               2.37.0      /usr/local/lib/python3.10/dist-packages pip
...
tabulate                                0.8.10      /usr/local/lib/python3.10/dist-packages pip
...

# az version -o table
Azure-cli    Azure-cli-core    Azure-cli-telemetry
-----------  ----------------  ---------------------
2.37.0       2.37.0            1.0.6

Could you run python3 -m pip list -v and check the tabulate 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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found