Reputation: 650
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.
Upvotes: 25
Views: 68056
Reputation: 13
Adding below line in the top into requirements.txt file works for me
azure-storage-blob
Upvotes: 0
Reputation: 19
I tried all the previous solutions, but none worked for me.
I fixed it by changing the order in my requirements.txt
file so that azure-storage-blob
has priorty.
...
azure-storage-blob
azure-functions
...
Upvotes: 0
Reputation: 21
I also got stuck with this error especially when I was deploying Azure Web App(it worked fine at local pc).
I think first of all you should check your installed packages list again.
For my case, I had azure-storage
and azure-storage-blob
which was strange as I remember only installing azure-storage-blob
. And I was getting exact same message as you.
like the answer from @Ivory, I also uninstalled both of them and tried installing all over again.
Then I got this error for pip install azure-storage
,
Collecting azure-storage
Using cached azure-storage-0.37.0.zip (4.3 kB)
ERROR: Command errored out with exit status 1:
command: /tmp/8da918957b4378c/antenv/bin/python3.8 -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-s_q2c_3c/azure-storage_855ccb98b522499ca9f42557f5036870/setup.py'"'"'; __file__='"'"'/tmp/pip-install-s_q2c_3c/azure-storage_855ccb98b522499ca9f42557f5036870/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-n2ov1yg9
cwd: /tmp/pip-install-s_q2c_3c/azure-storage_855ccb98b522499ca9f42557f5036870/
Complete output (19 lines):
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-install-s_q2c_3c/azure-storage_855ccb98b522499ca9f42557f5036870/setup.py", line 55, in <module>
raise RuntimeError(message)
RuntimeError:
Starting with v0.37.0, the 'azure-storage' meta-package is deprecated and cannot be installed anymore.
Please install the service specific packages prefixed by `azure` needed for your application.
The complete list of available packages can be found at:
https://aka.ms/azsdk/python/all
Here's a non-exhaustive list of common packages:
- [azure-storage-blob](https://pypi.org/project/azure-storage-blob) : Blob storage client
- [azure-storage-file-share](https://pypi.org/project/azure-storage-file-share) : Storage file share client
- [azure-storage-file-datalake](https://pypi.org/project/azure-storage-file-datalake) : ADLS Gen2 client
- [azure-storage-queue](https://pypi.org/project/azure-storage-queue): Queue storage client
You can see that there are error message telling that this azure-storage
is deprecated.
So what you should do is(If you have both azure-storage
and azure-storage-blob
like I did):
pip uninstall azure-storage
pip uninstall azure-storage-blob
pip install azure-storage-blob
again.from azure.storage.blob import BlobServiceClient
again, and it would work perfectly.I hope this can help who stumbles upon this problem.
Upvotes: 2
Reputation: 752
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
Upvotes: 38
Reputation: 81
In my case, I installed azure first and then I got this error. By doing the following steps, and it works fine now:
Upvotes: 5
Reputation: 650
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.
Upvotes: 1