Search code examples
python-3.xazureazure-storageazure-blob-storageconda

Where is the BlockBlobService Class Located in Python Azure Module?


I am pretty new to using the microsoft azure service and trying to follow the tutorial in https://learn.microsoft.com/en-us/azure/storage/blobs/storage-quickstart-blobs-python Using Python 3.5.6 in conda 4.5.11 distribution on a Windows PC.

The first problem I am facing while importing azure is I cannot see the version the usual way. That means

azure.__version__ 

gives an error.

Then, this line of the code gives me an error saying it can neither import names BlockBlobService, nor PublicAccess. Seems like both have been deprecated or I am myself using some old version.

from azure.storage.blob import BlockBlobService, PublicAccess  #Option 1

However, the following import is working.

from azure.storage.blob import BlobService #Option 2 

But the problem with this is after I create a local file and try to upload with a create_blob_from_path method (as advised in the tutorial), the method is either non-existent or deprecated.

I looked around the web for solution of this BlockBlobService issue, and seemed there has been a persistent confusion around the correct module hierarchy and class names to import. One user, for example, got some official documentation from the library which advised this, which also does not work.

from azure.storage import BlobService #Option 3

Still someone else reported some complaint with this, which is working on my system at least. But this does not import the needed Blob object.

import azure.storage.blob #Option 4

Further, according to this documentation, https://learn.microsoft.com/en-us/python/api/azure-storage-blob/azure.storage.blob.blockblobservice.blockblobservice?view=azure-python

the BlockBlobService class is located in azure.storage.blob.blockblobservice module. But the interpreter throws an import error when I try to import that as well.

Most of the proposed solutions are around some upgrading/downgrading of versions, but, silly me, somehow I cannot even find the version of the azure module like I do for other modules. Also, it seems many of the solutions are for pip3 running on Linux, whence I am using conda 4.5.11 on Windows. So how to make the azure API work?


Solution

  • On windows, you should use pip install azure.

    My environment is windows 10 with python 3.6.5, but I didn't use conda.

    First, in cmd, run pip install azure, screenshot as below: enter image description here

    Then in pycharm, try use the from xxx import xx, screenshots as below:

    For BlockBlobService: enter image description here

    For PublicAccess: enter image description here

    The BlockBlobService location: enter image description here