azure-sdk-for-python
azure-sdk-for-python copied to clipboard
ImportError: cannot import name 'RecoveryServicesBackupClient' from 'azure.mgmt.recoveryservicesbackup'
I have installed ansible in ubuntu so when i am running this task - name: resource group azure_rm_resourcegroup: name: New_acr_demo location: westus tags: environment: production
I end up with this error
The error was: ImportError: cannot import name 'RecoveryServicesBackupClient' from 'azure.mgmt.recoveryservicesbackup' (/usr/local/lib/python3.11/site-packages/azure/mgmt/recoveryservicesbackup/init.py) fatal: [localhost]: FAILED! => {"changed": false, "msg": "Failed to import the required Python library (ansible[azure] (azure >= 2.0.0)) Python /usr/local/bin/python. 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"}
I have tried importing these libraries from azure.mgmt.recoveryservicesbackup.activestamp import RecoveryServicesBackupClient import os import azure.mgmt.recoveryservicesbackup.activestamp.models as RecoveryServicesBackupModels
but i am still getting this error.
Expected behavior
The issue should have been resolved.
Hi can anyone help me on this.
Thanks for the feedback, we’ll investigate asap.
I have run the same task on azure cloudshell following the Microsoft azure documentation and after installing the azure modules and python libraries I still end up with the same error.
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ImportError: cannot import name 'RecoveryServicesBackupClient' from 'azure.mgmt.recoveryservicesbackup' (/home/shashwat_sharma/.local/lib/python3.9/site-packages/azure/mgmt/recoveryservicesbackup/init.py) fatal: [localhost]: FAILED! => {"changed": false, "msg": "Failed to import the required Python library (ansible[azure] (azure >= 2.0.0)) on Python /usr/bin/python3.9. 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"}
Hi, @Shashwat2712200
from azure.mgmt.recoveryservicesbackup import RecoveryServicesBackupClient should work with the latest release, please try reinstall the sdk: pip install azure.mgmt.recoveryservicesbackup==7.0.0 and also check whether the Python interpreter you're using is as expected.
Hi @Shashwat2712200. Thank you for opening this issue and giving us the opportunity to assist. To help our team better understand your issue and the details of your scenario please provide a response to the question asked above or the information requested above. This will help us more accurately address your issue.
I have checked the python interpreter it is working fine I am using these commands and then running the ansible-playbook:
pip3 install azure-mgmt-network azure-storage-blob azure-mgmt-automation azure-mgmt-core pip3 install azure-identity azure-storage-blob msrestazurepip3 install azure-mgmt-recoveryservicesbackup==7.0.0 azure-mgmt-compute==30.3.0 azure-mgmt-resource==23.1.0b2 azure-mgmt-recoveryservices==2.5.0 git clone https://github.com/Azure-Samples/azure-samples-python-management.git cd azure-samples-python-management/samples/recoveryservicesbackup pip install -r requirements.txt from azure.mgmt.recoveryservicesbackup.activestamp import RecoveryServicesBackupClient from azure.mgmt.recoveryservicesbackup import RecoveryServicesBackupClient import azure.mgmt.recoveryservicesbackup.activestamp.models as RecoveryServicesBackupModels
I end up with the same error mentioned above
@Shashwat2712200 That's where we addressed the issue, by installing sdk from the requirements.txt, you have reinstalled the azure-mgmt-recoveryservicesbackup with an older version 5.0.0. So I guess what you need to do is to just skip the step pip install -r requirements.txt or manually update this file to make sure it uses the latest sdk.
Hi @Shashwat2712200. Thank you for opening this issue and giving us the opportunity to assist. We believe that this has been addressed. If you feel that further discussion is needed, please add a comment with the text "/unresolve" to remove the "issue-addressed" label and continue the conversation.
/unresolve
I have tried this too pip install azure-mgmt-recoveryservicesbackup==7.0.0 and skipped the pip install -r requirements.txt. then i end up with this error.
The error was: ModuleNotFoundError: No module named 'azure.mgmt.recoveryservicesbackup.models'
I have taken every approach provided on the Internet by using commands. Can you look into it
import azure.mgmt.recoveryservicesbackup.models is incorrect, if there's such code in your sample, try update it to import azure.mgmt.recoveryservicesbackup.activestamp.models.
I have tried this but i end up with the same error.
Hi @Shashwat2712200 The code from ansible plugins might be the root of error https://github.com/ansible-collections/azure/blob/dev/plugins/module_utils/azure_rm_common.py#L252, and I noticed that the developer of ansible recommends using azure-mgmt-recoveryservicesbackup==3.0.0, you may need reinstall it with version 3.0.0 to get the fully support. If there're still conflicts, I'm afraid it will be necessary to manually modify the ansible plugin files in your environment.
Hi @Shashwat2712200. Thank you for opening this issue and giving us the opportunity to assist. We believe that this has been addressed. If you feel that further discussion is needed, please add a comment with the text "/unresolve" to remove the "issue-addressed" label and continue the conversation.
Hi @Shashwat2712200, since you haven’t asked that we /unresolve the issue, we’ll close this out. If you believe further discussion is needed, please add a comment /unresolve to reopen the issue.