我们可以导入azure.storage,但不能访问BlobService属性
文档说使用以下import语句:
from azure.storage import BlobService
Run Code Online (Sandbox Code Playgroud)
但是得到以下错误:
ImportError: cannot import name BlobService
Run Code Online (Sandbox Code Playgroud)
我们尝试了以下方法:
import azure.storage
...
foo = azure.storage.BlobService(...)
Run Code Online (Sandbox Code Playgroud)
但是收到了以下错误:
AttributeError: ‘module’ object has no attribute ‘BlobService’
Run Code Online (Sandbox Code Playgroud)
我们还用"azure.storage.blob"代替"azure.storage"尝试了上述所有内容
我们尝试更新azure-storage软件包,但它是最新的(版本0.30.0)
我们还尝试卸载azure-storage并安装整个azure包,但我们得到了相同的结果.我们尝试用pip和conda安装它们,但两次都是相同的结果.
我知道输出表明此版本的azure.storage没有BlobService属性,但文档明确指出要从那里导入.
我参考了 Microsoft 的适用于 Python 的 Azure Blob 存储客户端库 v12的快速入门指南。它详细说明了如何上传 blob,但我想删除 blob。这个答案建议使用:
from azure.storage.blob import BlobService
blob_service = BlobService(account_name=accountName, account_key=accountKey)
blob_service.delete_blob(container_name, blob_name)
Run Code Online (Sandbox Code Playgroud)
但是,我尝试过,但出现以下错误:
ImportError: cannot import name 'BlobService' from 'azure.storage.blob'
Run Code Online (Sandbox Code Playgroud)
另一个答案建议使用from azure.storage.blob import BlockBlobService,但我也得到了与ImportError上面相同的结果。
我搜索了 Stackoverflow 以解决上述错误,并遇到了这个答案,它建议使用旧版本的库 ( azure-storage) 和另一个建议安装整个azure库的答案,但我想改用最新的库。
如何使用最新的azure-storage-blob库上传文件并删除 blob ?或者,如果我是 2019 年的新用户,并且正在遵循上述快速入门指南,但我想使用azure-storage这里的许多答案推荐的旧库,我该怎么做?