Azure BlobServiceClient出现导入错误(偶尔)

2024-04-25 21:34:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我得到了一个

from azure.storage.blob import BlobServiceClient

不过,我意识到,当我将依赖项安装为

pip install azure-storage-blob
pip install azure-storage

但当我像这样安装它们时就不行了

pip install azure-storage
pip install azure-storage-blob

pip freeze在这两种情况下显示相同的库

azure-common==1.1.23
azure-core==1.0.0
azure-nspkg==3.0.2
azure-storage==0.36.0
azure-storage-blob==12.0.0
certifi==2019.9.11
cffi==1.13.2
chardet==3.0.4
cryptography==2.8
idna==2.8
isodate==0.6.0
msrest==0.6.10
oauthlib==3.1.0
pycparser==2.19
python-dateutil==2.8.1
requests==2.22.0
requests-oauthlib==1.3.0
six==1.13.0
urllib3==1.25.7

第二种方法是有效的,但是我担心以后会出现错误。 Azure库有问题吗?或者我在这里遗漏了什么?你知道吗


Tags: installpipfromcoreimport情况storagecommon
3条回答

请卸载azure-storage-blobazure-storage。你知道吗

然后使用以下命令:

pip install azure-storage-blob==12.0.0

BlobServiceClient位于latest version 12.0.0 of azure-storage-blob

azure存储包已弃用。你知道吗

请用这些包裹

https://pypi.org/project/azure-storage-blob/

https://pypi.org/project/azure-storage-queue/

https://pypi.org/project/azure-storage-file-share/

pip install azure-storage-blob就足够了,不需要安装azure-storage。你知道吗

同样,如果正在处理队列和文件,请安装它们。 如果您仍然面临这个问题,请告诉我(我为azure sdk团队工作)

正如@GauravMantri所说,如果您想使用from azure.storage.blob import BlobServiceClient,您只需安装^{}包,因为包azure-storage-blob^{}不同,但它们使用相同的名称空间作为前缀。你知道吗

所以不同的安装顺序会得到不同的结果。例如,如下所示。你知道吗

pip install azure-storage-blob
pip install azure-storage

后面的包azure-storage安装将覆盖示例名称空间azure.storage.blob,但不包括类BlobServiceClient,只包括azure-storage的类BlockBlobService。你知道吗

作为参考,GitHub repo^{}README.md也注意到如下图所示,当您想要使用azure-storage-blob时,必须首先卸载azure-storage<=0.36.0。你知道吗

enter image description here

因此,如果使用这些包的不正确安装顺序作为示例,则必须首先卸载azure-storage,然后安装azure-storage-blob 再次避免以后可能出现的错误。你知道吗

相关问题 更多 >