Azure/azure-cli

With Azure CLI 2.0.70 az cli commands are not working when run from within Python (3.6.8) virtual env on CentOS 7.5

mandarinamdar opened this issue · 6 comments

Describe the bug
With Azure CLI 2.0.70 az cli commands are not working when run from within Python (3.6.8) virtual env on CentOS 7.5.
Any az cli command is throwing error when run from within Python (3.6.8) virtual env on CentOS 7.5

To Reproduce
Install az cli based on documented steps at https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-yum?view=azure-cli-latest

Install Python 3.6.8 on CentOS based 7.5
create python virtual environment
cd ~
python3.6 -m venv env
Activate the Python Virtual Environment :- source ~/env/bin/activate
az login command throws following error from within python virtual environment

Traceback (most recent call last):
File "/usr/lib64/python3.6/runpy.py", line 183, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
File "/usr/lib64/python3.6/runpy.py", line 109, in _get_module_details
import(pkg_name)
File "/usr/lib64/az/lib/python2.7/site-packages/azure/init.py", line 1, in
import('pkg_resources').declare_namespace(name)
File "/usr/lib64/az/lib/python2.7/site-packages/pkg_resources/init.py", line 24, in
import re
File "/usr/lib64/python3.6/re.py", line 142, in
class RegexFlag(enum.IntFlag):
AttributeError: module 'enum' has no attribute 'IntFlag'

Expected behavior
az cli commands should work without giving error.

Environment summary
Install Method
sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
sudo sh -c 'echo -e "[azure-cli]\nname=Azure CLI\nbaseurl=https://packages.microsoft.com/yumrepos/azure-cli\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/azure-cli.repo'
sudo yum install azure-cli

OS :- CentOS based 7.5 Image on Azure VM

Python 3.6.8 installed using
sudo yum install epel-release
sudo yum install python36 python36-devel python36-setuptools
python36 --version

python virtual environment created using
cd ~
python3.6 -m venv env
source env/bin/activate
python --version

Additional context
if the az cli earlier version 2.0.69 is installed the same works fine

wget https://packages.microsoft.com/yumrepos/azure-cli/azure-cli-2.0.69-1.el7.x86_64.rpm
sudo yum install azure-cli-2.0.69-1.el7.x86_64.rpm

az cli (2.0.69) commands works normally with same OS environment in a python 3.6.8 virtual environment

@zikalino, could you please take a look?

I am getting this exact issue:

  • CentOS 7.6
  • Python 3.6 (venv active)
  • Azure-cli 2.0.71

Is there any update as to the cause?

Hello, I am getting exactle the same error on Fedora 30 and 31. I can install the az package, but then any command ends with the same issue.

$ az login
Traceback (most recent call last):
  File "/usr/lib64/python3.7/runpy.py", line 183, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/usr/lib64/python3.7/runpy.py", line 109, in _get_module_details
    __import__(pkg_name)
  File "/usr/lib64/az/lib/python2.7/site-packages/azure/__init__.py", line 1, in <module>
    __import__('pkg_resources').declare_namespace(__name__)
  File "/usr/lib64/az/lib/python2.7/site-packages/pkg_resources/__init__.py", line 24, in <module>
    import re
  File "/usr/lib64/python3.7/re.py", line 143, in <module>
    class RegexFlag(enum.IntFlag):
AttributeError: module 'enum' has no attribute 'IntFlag'

@fengzhou-msft please take a look.

Hitting the same issue.

RPM installed azure cli previous to 2.0.76 is using Python 2 with a bunch of site-packages, if python command in your system defaults to Python 3, it will cause issues. We just released the fix with 2.0.76 to use the correct python2 command. Please upgrade to 2.0.76 and retry.