16

We are able to import azure.storage, but not access the BlobService attribute

The documentation says to use the following import statement:

from azure.storage import BlobService

But that get's the following error:

ImportError: cannot import name BlobService

We tried the following:

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

But that received the following error:

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

We also tried all of the above with "azure.storage.blob" instead of "azure.storage"

We tried updating azure-storage package but it is up to date (version 0.30.0)

We also tried uninstalling azure-storage and installing the entire azure package, but we got the same results. We tried installing them with both pip and conda, but same results both times.

I am aware that the output suggests that this version of azure.storage has no BlobService attribute, but the documentation clearly states to import from there.

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

user3664942
  • 215
  • 1
  • 2
  • 10
  • You test your code on Windows or Linux? And have you try to use virtual environment https://azure.microsoft.com/en-us/documentation/articles/web-sites-python-create-deploy-django-app/#troubleshooting---virtual-environment ? – Gary Liu Feb 23 '16 at 06:45
  • I'm running a Windows 10 VM on a Macbook Pro 15-inch using Parallels Desktop. I am using an Anaconda virtual environment, which was listed in the [documentation](https://azure.microsoft.com/en-gb/documentation/articles/python-how-to-install/#where-to-get-python) as one of the acceptable python distributions. I'll try a different distribution to see if anything changes – user3664942 Feb 23 '16 at 09:41
  • new Azure Storage documentation is available here: https://media.readthedocs.org/pdf/azure-storage/latest/azure-storage.pdf – Saher Ahwal Jan 27 '17 at 19:25

4 Answers4

26

If you want to use BlobService, you could install package azure.storage 0.20.0, there is BlobService in that version. In the latest azure.storage 0.30.0 , BlobSrvice is split into BlockBlobService, AppendBlobService, PageBlobService object, you could use BlockBlobService replace BlobService.

Paolo
  • 21,270
  • 6
  • 38
  • 69
Lily_user4045
  • 795
  • 4
  • 11
11

It's possible the library has changed since that tutorial was published, but...

I just tried this a few moments ago, successfully:

from azure.storage.blob import BlockBlobService

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

And I installed Azure storage locally via:

pip install azure-storage

I was able to test this by downloading an object from storage:

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

Note: You could import PageBlobService in similar fashion, but you might not find that too valuable, since page blobs are primarily for vhd's.

David Makogon
  • 69,407
  • 21
  • 141
  • 189
  • 2
    This is correct. The 0.30.0 was released last week per [this announcement](https://github.com/Azure/azure-storage-python/issues/132). There's a totally up-to-date tutorial on using blobs [here](https://azure.microsoft.com/en-us/documentation/articles/storage-python-how-to-use-blob-storage/). The tutorial you looked at looks like it was on pre-0.20.0 versions, so if you want to use that exactly as written you'll need to regress pretty far. I follow up with its writers to see if they can update it. – Emily Gerner Feb 23 '16 at 18:18
  • If my data_path is ``` "containername" => "blobname" = > "folder" => "subfolder" => "subfolder" =>"dataset.csv"``` How can I access ? – Hayat Jan 31 '20 at 12:54
  • @Hayat - please post a new question if you're having trouble accessing a specific blob, since your question is beyond the scope of this particular question. Also note that there are no "subfolders" in Azure Storage (unless using ADLS) - just containers; those "folders" are just part of a long filename with delimiters. – David Makogon Jan 31 '20 at 14:36
4

I had the same issue after using pip to install the azure package and, as the chosen answer suggests, this can be fixed by installing azure.storage 0.33.0.

However, if you're using pip, you might need to use the "--upgrade" option for it to install properly (this was my experience):

pip install azure-storage --upgrade
voyager
  • 333
  • 2
  • 10
2

I had version 1.0.3 installed (which includes azure.storage version 0.20) on Ubuntu server 16.04 LTS and pip only reinstalled version 0.20 of azure.storage when I uninstalled and reinstalled the azure package. This was according to the pypi page for the azure package v. 2.0.0rc6 which recommends that to upgrade from 1.0.3 to version 2 you should do

sudo pip3 uninstall azure
sudo pip3 install azure

pypi/azure

Instead, this worked for me,

sudo pip3 uninstall azure
sudo pip3 install azure==2.0.0rc6
larslovlie
  • 189
  • 1
  • 2
  • 10