'error importing 'BlobServiceClient' from 'azure.storage.blob'

I have the following line of code:

from azure.storage.blob import BlobServiceClient

I get the following error:

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)

I have this error BOTH on PythonAnywhere and on my local machine. I am following the tutorial here

I have read through this post on github but to no avail.

What is missing? The objective i am trying to accomplish is to access a blob in a container when I have a URI and a shared key.

Appreciate any help.



Solution 1:[1]

Can you check pip list and make sure you have the latest version of azure-storage-blob i.e >= 12.0.0?

BlobServiceClient is introduced in 12.0.0.

If you have an older version, do pip install azure-storage-blob --upgrade

Also, azure-storage-blob v 12.0.0 and above is moved to a different repository https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/storage/azure-storage-blob

EDIT: azure-storage-blob >= 12.0 is not compatible with the azure-storage meta package in case the issue persists after installing the latest major version of azure-storage-blob

Solution 2:[2]

In my case, I installed azure first and then I got this error. By doing the following steps, and it works fine now:

  1. Uninstall azure-storage-blob using: pip uninstall azure-storage-blob.
  2. Reinstall azure-storage-blob using: pip install azure-storage-blob.

Solution 3:[3]

It appears the issue was either with the version of azure-storage-blob that I was using or the order in which I was installing the other azure libraries (common, core, etc). I uninstalled everything and just installed azure-storage-blob and it worked.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Ivory lu
Solution 3 mbyamukama