No module named azure.common

Viewed 80

Why am I getting the error no module named azure.common. I've installed it already but I still get the error.

ModuleNotFoundError: No module named 'azure.common'

sh-4.4# pip3.6 list | grep common
azure-common                          1.1.28
azure-storage-common                  1.4.2



sh-4.4# pip3.8 list | grep common
azure-common                          1.1.28
azure-storage-common                  1.4.2

Any idea where exactly it is looking for azure.common and where should I install it?

Identity added: /tmp/ansible-runner20220907-326-1noxw49/artifacts/result/ssh_key_data (/tmp/ansible-runner20220907-326-1noxw49/artifacts/result/ssh_key_data)
[DEPRECATION WARNING]: Ansible will require Python 3.8 or newer on the 
controller starting with Ansible 2.12. Current version: 3.6.8 (default, Jan 14 
2022, 11:04:20) [GCC 8.5.0 20210514 (Red Hat 8.5.0-7)]. This feature will be 
removed from ansible-core in version 2.12. Deprecation warnings can be disabled
 by setting deprecation_warnings=False in ansible.cfg.
/usr/local/lib/python3.6/site-packages/ansible/parsing/vault/__init__.py:44: CryptographyDeprecationWarning: Python 3.6 is no longer supported by the Python core team. Therefore, support for it is deprecated in cryptography and will be removed in a future release.
  from cryptography.exceptions import InvalidSignature
ansible-playbook [core 2.11.12] 
  config file = /root/.ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.6/site-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible-playbook
  python version = 3.6.8 (default, Jan 14 2022, 11:04:20) [GCC 8.5.0 20210514 (Red Hat 8.5.0-7)]
  jinja version = 3.0.3
  libyaml = True
Using /root/.ansible.cfg as config file
host_list declined parsing /tmp/ansible-runner20220907-326-1noxw49/inventory/hosts as it did not pass its verify_file() method
script declined parsing /tmp/ansible-runner20220907-326-1noxw49/inventory/hosts as it did not pass its verify_file() method
auto declined parsing /tmp/ansible-runner20220907-326-1noxw49/inventory/hosts as it did not pass its verify_file() method
Parsed /tmp/ansible-runner20220907-326-1noxw49/inventory/hosts inventory source with ini plugin
[WARNING]: While constructing a mapping from /tmp/ansible-runner-
git20220907-328-r4mshj/azure_sg_create.yaml, line 36, column 7, found a
duplicate dict key (azure_vm_network_interface). Using last defined value only.
redirecting (type: modules) ansible.builtin.azure_rm_networkinterface_info to azure.azcollection.azure_rm_networkinterface_info
redirecting (type: modules) ansible.builtin.azure_rm_securitygroup to azure.azcollection.azure_rm_securitygroup
redirecting (type: modules) ansible.builtin.azure_rm_securitygroup to azure.azcollection.azure_rm_securitygroup
redirecting (type: modules) ansible.builtin.azure_rm_resource_info to azure.azcollection.azure_rm_resource_info
redirecting (type: modules) ansible.builtin.azure_rm_networkinterface to azure.azcollection.azure_rm_networkinterface
Skipping callback 'awx_display', as we already have a stdout callback.
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
 
PLAYBOOK: azure_sg_create.yaml *************************************************
1 plays in azure_sg_create.yaml
 
PLAY [localhost] ***************************************************************
META: ran handlers
 
TASK [Get facts by name] *******************************************************
task path: /tmp/ansible-runner-git20220907-328-r4mshj/azure_sg_create.yaml:18
 
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: root
<localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /tmp/.ansible_remote_tmp `"&& mkdir "` echo /tmp/.ansible_remote_tmp/ansible-tmp-1662559522.4644003-30346-31917676404938 `" && echo ansible-tmp-1662559522.4644003-30346-31917676404938="` echo /tmp/.ansible_remote_tmp/ansible-tmp-1662559522.4644003-30346-31917676404938 `" ) && sleep 0'
Using module file /root/.ansible/collections/ansible_collections/azure/azcollection/plugins/modules/azure_rm_virtualmachine_info.py
<localhost> PUT /tmp/.ansible_local_tmp/ansible-local-30296sqivv1jk/tmp_vbwz1a0 TO /tmp/.ansible_remote_tmp/ansible-tmp-1662559522.4644003-30346-31917676404938/AnsiballZ_azure_rm_virtualmachine_info.py
<localhost> EXEC /bin/sh -c 'chmod u+x /tmp/.ansible_remote_tmp/ansible-tmp-1662559522.4644003-30346-31917676404938/ /tmp/.ansible_remote_tmp/ansible-tmp-1662559522.4644003-30346-31917676404938/AnsiballZ_azure_rm_virtualmachine_info.py && sleep 0'
<localhost> EXEC /bin/sh -c '/usr/bin/python3.6 /tmp/.ansible_remote_tmp/ansible-tmp-1662559522.4644003-30346-31917676404938/AnsiballZ_azure_rm_virtualmachine_info.py && sleep 0'
<localhost> EXEC /bin/sh -c 'rm -f -r /tmp/.ansible_remote_tmp/ansible-tmp-1662559522.4644003-30346-31917676404938/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
Traceback (most recent call last):
  File "/tmp/ansible_azure.azcollection.azure_rm_virtualmachine_info_payload_zdtmpkmo/ansible_azure.azcollection.azure_rm_virtualmachine_info_payload.zip/ansible_collections/azure/azcollection/plugins/module_utils/azure_rm_common.py", line 234, in <module>
    from azure.common.credentials import ServicePrincipalCredentials, UserPassCredentials
ModuleNotFoundError: No module named 'azure.common'
fatal: [localhost -> localhost]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "ad_user": null,
            "adfs_authority_url": null,
            "api_profile": "latest",
            "auth_source": "auto",
            "cert_validation_mode": null,
            "client_id": null,
            "cloud_environment": "AzureCloud",
            "log_mode": null,
            "log_path": null,
            "name": "Ubuntu973",
            "password": null,
            "profile": null,
            "resource_group": "cloud-shell-storage-centralindia",
            "secret": null,
            "subscription_id": null,
            "tags": null,
            "tenant": null
        }
    },
    "msg": "Failed to import the required Python library (ansible[azure] (azure >= 2.0.0)) on a3b2d24ea52b's Python /usr/bin/python3.6. Please read the module documentation and install it in the appropriate location. If the required library is installed, but Ansible is using the wrong Python interpreter, please consult the documentation on ansible_python_interpreter"
}
 
PLAY RECAP *********************************************************************
localhost                  : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   
1 Answers

After reproducing from my end, I could able to see everything works fine. Make sure you follow the below steps.

  1. Make sure you update python and pip to latest. I can see you receive [DEPRECATION WARNING]: Ansible will require Python 3.8 or newer on the controller starting with Ansible 2.12. and the current version you are using is 3.6 Current version: 3.6.8.

    To update pip to latest use

    python -m pip install --upgrade pip
    
  2. In general, mostly this type error occurs when there is no virtual environment present in your environment and the desired package is not installed.

    Install virtual environment

    pip3 install virtualenv
    

    Create Virtual Environment

    Python3 -m venv .venv
    

    Activate Virtual Environment

    .venv\Scripts\Activate.ps1
    
  3. If it still doesn't work and the package has already installed earlier, then try uninstalling and then reinstalling the package.

You can also try referring a similar issue from DEPRECATION WARNING for Ansible for Python 3.7.- GitHub

Related