我正在尝试使用蔚蓝的 get_client_from_cli_profile 创建 ComputeClient ,就像我在Azure docs上看到的那样。
import os
from getpass import getpass
from azure.mgmt.compute import ComputeManagementClient
from azure.common.client_factory import get_client_from_cli_profile
login = input("Input your login : ")
pwd = getpass("Input your password : ")
print("Logging to azure...")
command = "az login -u {} -p {}".format(login, pwd)
os.system(command)
print("Logged in !")
print("Getting ressource client...")
resource_client = get_client_from_cli_profile(ComputeManagementClient)
print("Client acquired !")
但是,在 get_client_from_cli_profile 期间出现错误,提示未安装azure-core ...
Traceback (most recent call last):
File "test.py", line 14, in <module>
resource_client = get_client_from_cli_profile(ComputeManagementClient)
File "/usr/local/lib/python3.6/dist-packages/azure/common/client_factory.py", line 86, in get_client_from_cli_profile
with_tenant=True,
File "/usr/local/lib/python3.6/dist-packages/azure/common/credentials.py", line 99, in get_azure_cli_credentials
cred = _CliCredentials(profile, resource)
File "/usr/local/lib/python3.6/dist-packages/azure/common/credentials.py", line 50, in __init__
raise ImportError("You need to install 'azure-core' to use this feature")
ImportError: You need to install 'azure-core' to use this feature
这是我要求中的包裹:
azure-cli-core
azure
azure-core
我已验证该软件包已正确安装,并且如果我有权读取文件夹和文件,并且一切对我来说都很好:
$ pip3 show azure-core
Name: azure-core
Version: 1.2.2
Summary: Microsoft Azure Core Library for Python
Home-page: https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/core/azure-core
Author: Microsoft Corporation
Author-email: azpysdkhelp@microsoft.com
License: MIT License
Location: /home/non/.local/lib/python3.6/site-packages
Requires: six, requests
Required-by:
$ ls -la /usr/local/lib/python3.6/dist-packages/azure/common/
total 48
drwxrwsrwx 3 root staff 4096 févr. 27 10:54 .
drwxrwsrwx 19 root staff 4096 févr. 27 10:54 ..
-rwxrwxrwx 1 root staff 10452 févr. 27 10:54 client_factory.py
-rwxrwxrwx 1 root staff 755 févr. 27 10:54 cloud.py
-rwxrwxrwx 1 root staff 4256 févr. 27 10:54 credentials.py
-rwxrwxrwx 1 root staff 805 févr. 27 10:54 exceptions.py
-rwxrwxrwx 1 root staff 1358 févr. 27 10:54 __init__.py
drwxrwsrwx 2 root staff 4096 févr. 27 10:54 __pycache__
-rwxrwxrwx 1 root staff 328 févr. 27 10:54 _version.py
在启动脚本之前,我尝试过 az登录,但这并没有改变结果。
答案 0 :(得分:0)
首先,您不需要“ azure-core”就可以在计算客户端上使用此方法,为此我创建了一个问题: https://github.com/Azure/azure-sdk-for-python/issues/10041
但是,仍然如显示的那样安装了“ azure-core”,这令人不安。您能否在问题跟踪器上创建问题,以便我们进行更深入的对话? https://github.com/Azure/azure-sdk-for-python/issues
编辑:您实际上点击了: https://github.com/Azure/azure-sdk-for-python/issues/9195
请不要使用不适用于当前“ azure-cli-core”的“ azure”元软件包,而应安装“ azure-mgmt-compute”,所以您应该安装以下软件包:>
azure-mgmt-compute
azure-cli-core
azure-core # Should not be necessary, bug 10041
如果不能解决您的问题,请随时打开问题