【问题标题】:error importing 'BlobServiceClient' from 'azure.storage.blob'从“azure.storage.blob”导入“BlobServiceClient”时出错
【发布时间】:2020-03-05 04:44:27
【问题描述】:

我有以下代码行:

from azure.storage.blob import BlobServiceClient

我收到以下错误:

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)

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

我已经阅读了 github 上的this post,但无济于事。

缺少什么?我要实现的目标是当我有 URI 和共享密钥时访问容器中的 blob。

感谢任何帮助。

【问题讨论】:

  • 我无法在 PythonAnywhere 上重现它。我所做的是:pip3.7 install azure-storage-blob --user 在 bash 控制台中,然后是 python3.7 -c "from azure.storage.blob import BlobServiceClient,它工作得很好。

标签: python azure azure-storage azure-blob-storage


【解决方案1】:

您能否检查pip list 并确保您拥有最新版本的 azure-storage-blob,即 >= 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 模块错误。
  • @Ateeb BaseBlobService 从 12.0.0 开始弃用 - 考虑使用 BlobServiceClient
【解决方案2】:

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

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

【讨论】:

    【解决方案3】:

    看来问题出在我使用的 azure-storage-blob 版本或我安装其他 azure 库(通用库、核心库等)的顺序上。我卸载了所有东西,只安装了 azure-storage-blob 并且它工作正常。

    【讨论】:

      猜你喜欢
      • 2016-09-18
      • 2020-12-01
      • 2019-12-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-07
      • 2021-11-03
      • 2010-10-12
      相关资源
      最近更新 更多