Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
alexpilon666 opened this issue Jun 10, 2022 · 6 comments
Assignees
Labels
ARM az resource/group/lock/tag/deployment/policy/managementapp/account management-group Auto-Assign Auto assign by bot customer-reported Issues that are reported by GitHub users external to the Azure organization.
Milestone

Comments

@alexpilon666
Copy link

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: #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

@ghost ghost added customer-reported Issues that are reported by GitHub users external to the Azure organization. Auto-Assign Auto assign by bot ARM az resource/group/lock/tag/deployment/policy/managementapp/account management-group labels Jun 10, 2022
@ghost ghost assigned zhoxing-ms Jun 10, 2022
@ghost ghost added this to the Backlog milestone Jun 10, 2022
@yonzhan
Copy link
Collaborator

yonzhan commented Jun 10, 2022

ARM

@alexpilon666
Copy link
Author

Any news on this issue ?
We're in the process of migrating from Centos7 to Ubuntu 22.04LTS, and this issue is actively blocking our progress as we heavily rely on Azure CLI for our day-to-day work.

@zhoxing-ms
Copy link
Contributor

zhoxing-ms commented Jun 21, 2022

"/usr/local/lib/python3.10/dist-packages/tabulate.py"

I guess it's related to issue #19640 @jiasli Could you please help have a look?

@alexpilon666
Copy link
Author

@zhoxing-ms , @jiasli , in my case, even though yes I am running on Ubuntu (not Debian directly), AzureCLI was installed via Python, not via the package manager.

This is how we have installed it:
Note: The lack of sudo works because this is running inside an Ubuntu 22.04LTS container. All commands are executed as root, and when running AzureCLI post-install we are also running as root.

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

@jiasli
Copy link
Member

jiasli commented 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 #20476.

Please also note that we recommend using the official Azure CLI DEB package to install. Please see #19640.

@alexpilon666
Copy link
Author

alexpilon666 commented 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ARM az resource/group/lock/tag/deployment/policy/managementapp/account management-group Auto-Assign Auto assign by bot customer-reported Issues that are reported by GitHub users external to the Azure organization.
Projects
None yet
Development

No branches or pull requests

4 participants