python - 从 msrestazure.azure_active_directory 导入(ModuleNotFoundError : No module named 'msrestazure'

标签 python azure virtual-machine azure-python-sdk

我已编写代码来列出 Azure 虚拟机。但我收到这个错误。当我尝试 pip install msrest 或 pip install msrestazure 时。这些命令都不起作用。它既不给出错误也不开始安装。 enter image description here

Traceback (most recent call last): File "d:\FYP\FYP\AzureVms.py", line 1, in from azure.common.credentials import ServicePrincipalCredentials File "d:\FYP\FYP\Azure\lib\site-packages\azure\common\credentials.py", line 171, in raise ImportError("You need to install 'msrestazure' to use this feature") ImportError: You need to install 'msrestazure' to use this feature

from azure.common.credentials import ServicePrincipalCredentials
from azure.mgmt.compute import ComputeManagementClient

credential = ServicePrincipalCredentials(client_id='XXXX', secret='XXXX',tenant='XXXX')
compute_client = ComputeManagementClient(
    credential, 'XXXX')

def list_virtual_machines():
    for vm in compute_client.virtual_machines.list_all():
        print(vm.name)

最佳答案

ModuleNotFoundError: No module named 'msrestazure'

在您的 python 项目中,使用以下命令安装 Pandas 库和 msrestazure python:

pip install msrestazure

安装msrestazure python库后,上述错误将得到解决。

<小时/>

要使用 python 代码获取/打印虚拟机详细信息,请参阅此 microsoft documentation给出了实际代码。

关于python - 从 msrestazure.azure_active_directory 导入(ModuleNotFoundError : No module named 'msrestazure' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71657663/

相关文章:

python - 用于在 jupyter 中进行内联绘图的 matplotlib 后端是什么

python - 类级别的 mock.patch.dict - python 单元测试

python - 从压缩字节加载 numpy 数组

azure - Google Chrome 已阻止 azure.microsoft.com 域

python - 如何修复 Sagemath 中函数 mod 的错误?

c# - 从EventHub读取特定消息

azure - 如何在 Azure 上部署 keycloak docker 容器?

iphone - 如何为 iPhone 创建远程虚拟机客户端? (在 XCode 中)

azure - Terraform:如何使用 Azure Monitor Agent 为 Azure Windows VM 启用 VM Insights?

visual-studio - Azure错误: SubscriptionNotAuthorizedForImage when deploying a Visual Studio Community VM from Azure Marketplace