从“azure.storage.blob”导入“BlobServiceClient”时出错

mby*_*ama 7 python azure azure-storage azure-storage-blobs azure-blob-storage

我有以下代码行:

from azure.storage.blob import BlobServiceClient
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

from azure.storage.blob import BlobServiceClient
ImportError: cannot import name 'BlobServiceClient' from 'azure.storage.blob' (/home/user-name/.local/lib/python3.7/site-packages/azure/storage/blob/__init__.py)
Run Code Online (Sandbox Code Playgroud)

我在 PythonAnywhere 和我的本地机器上都有这个错误。我正在关注这里的教程

我已经通读了 github 上的这篇文章,但无济于事。

有什么不见了?我试图实现的目标是当我有一个 URI 和一个共享密钥时访问容器中的 blob。

感谢任何帮助。

rak*_*h91 17

您能否检查pip list并确保您拥有最新版本的 azure-storage-blob ie >= 12.0.0?

BlobServiceClient 是在 12.0.0 中引入的。

如果您有旧版本,请执行 pip install azure-storage-blob --upgrade

此外,azure-storage-blob v 12.0.0 及更高版本已移至不同的存储库 https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/storage/azure-storage-blob

  • 我有 azure 存储版本 12.5.0,但仍然出现无法导入 baseblobservice 模块错误。 (3认同)
  • @Ateeb BaseBlobService 从 12.0.0 开始已弃用 - 考虑使用 BlobServiceClient (2认同)

小智 5

就我而言,我首先安装了 azure,然后收到此错误。通过执行以下步骤,现在可以正常工作了:

  1. 使用以下命令卸载 azure-storage-blob:pip uninstall azure-storage-blob。
  2. 使用以下命令重新安装 azure-storage-blob:pip install azure-storage-blob。