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

Azure BlobServiceClient gives import error (occasionally)

我得到一个 ImportError

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 库有问题还是我遗漏了什么?

请卸载azure-storage-blobazure-storage

然后使用这个命令:

pip install azure-storage-blob==12.0.0

BlobServiceClientlatest version 12.0.0 of azure-storage-blob

正如@GauravMantri 所说,您只需安装 azure-storage-blob package if you want to use from azure.storage.blob import BlobServiceClient, because the package azure-storage-blob is different with azure-storage,但它们使用与前缀相同的命名空间。

所以不同的安装顺序会得到不同的结果。例如,如下。

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

后面的包azure-storage安装会覆盖示例命名空间azure.storage.blob,但不包括classBlobServiceClient,只有classBlockBlobServiceazure-storage

作为参考,GitHub repo Azure/azure-storage-python/tree/master/azure-storage-blobREADME.md也注意下图,你必须先卸载azure-storage<=0.36.0才能使用azure-storage-blob.

所以如果你使用这些包的安装顺序不正确作为我的例子,你必须先卸载 azure-storage 然后安装 azure-storage-blob 再次避免以后可能出现的错误。

已弃用包 azure-storage。

请使用这些包

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 团队工作)