我已编写代码来列出 Azure 虚拟机。但我收到这个错误。当我尝试 pip install msrest 或 pip install msrestazure 时。这些命令都不起作用。它既不给出错误也不开始安装。
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/