如何在python中导入Azure BlobService?

时间:2016-02-22 16:13:20

标签: python azure azure-storage-blobs

我们可以导入azure.storage,但不能访问BlobService属性

文档说使用以下import语句:

from azure.storage import BlobService

但是会出现以下错误:

ImportError: cannot import name BlobService

我们尝试了以下方法:

import azure.storage
...
foo = azure.storage.BlobService(...)

但是收到了以下错误:

AttributeError: ‘module’ object has no attribute ‘BlobService’

我们还尝试了以上所有" azure.storage.blob"而不是" azure.storage"

我们尝试更新azure-storage软件包,但它是最新的(版本0.30.0)

我们还尝试卸载azure-storage并安装整个azure包,但我们得到了相同的结果。我们尝试使用pip和conda安装它们,但两次都会产生相同的结果。

我知道输出表明此版本的azure.storage没有BlobService属性,但文档明确指出要从那里导入。

https://azure.microsoft.com/en-us/documentation/articles/machine-learning-data-science-create-features-blob/

4 个答案:

答案 0 :(得分:17)

是的,如果您想使用BlobService,则可以安装包azure.storage 0.20.0,该版本中有BlobService。在最新的azure.storage 0.30.0中,BlobSrvice被拆分为BlockBlobService, AppendBlobService, PageBlobService个对象,您可以使用BlockBlobService替换BlobService。有很多文章需要更新内容。

答案 1 :(得分:8)

自该教程发布以来,该库可能已发生变化,但是......

我刚刚尝试过这个,成功:

from azure.storage.blob import BlockBlobService

blob_service = BlockBlobService(account_name="...",account_key="...")

我通过以下方式在本地安装了Azure存储:

pip install azure-storage

我可以通过从存储中下载对象来测试它:

blob_service.get_blob_to_path("containername","blobname","localfilename")

注意:您可以以类似的方式导入PageBlobService,但您可能没有发现它太有价值,因为页面blob主要用于vhd。

答案 2 :(得分:2)

我在Ubuntu服务器16.04 LTS上安装了1.0.3版本(其中包括azure.storage版本0.20),并且当我卸载并重新安装azure软件包时,仅重新安装了0.20版本的azure.storage。这是根据azure软件包v.2.0.0rc6的pypi页面,它推荐从1.0.3升级到版本2你应该做

sudo pip3 uninstall azure
sudo pip3 install azure

pypi/azure

相反,这对我有用,

sudo pip3 uninstall azure
sudo pip3 install azure==2.0.0rc6

答案 3 :(得分:1)

使用pip安装azure软件包之后我遇到了同样的问题,正如所选答案所示,可以通过安装azure.storage 0.33.0来解决这个问题。

但是,如果您正在使用pip,则可能需要使用" - upgrade"正确安装的选项(这是我的经验):

pip install azure-storage --upgrade