azure-storage-python: cannot import name 'BlockBlobService'
Hi,
I have azure-storage-blob version 0.37.1 and still i get an error when i import BlockBlobService.
from azure.storage.blob import BlockBlobService # import azure sdk packages
Error message: ImportError: cannot import name ‘BlockBlobService’
Here is a list of existing azure storage packages in my current virtual environment:
azure-storage-blob==0.37.1 azure-storage-common==0.37.1 azure-storage-nspkg==2.0.0
How can i fix this?
Thanks.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 4
- Comments: 42 (9 by maintainers)
Hi @melzoghbi, I’m unable to reproduce this problem. It does not seem to be a problem with the storage package. Could you please try again with a different virtual environment? Thanks!
I think there is some dependency bug in the source code (version azure-storage-blob==2.1.0 ) of blockblobservice.py and init.py under site-packages/azure/storage/blob/ directory. Because when I type in
from azure.storage.blob.blockblobservice import BlockBlobService
it worked.Ok. I’ve been able to figure out how to get
BlobServiceClient
andBlockBlobService
running in Azure Notebooks (thanks in part to @harmonyliu!):!pip uninstall azure -y
!pip install azure==4.0.0
from azure.storage.blob.blockblobservice import BlockBlobService
from azure.storage.blob import BlobServiceClient
Hope this helps@melzoghbi which version of Python are you using?
For me it worked after I installed azure package: pip install azure
I noticed that it uninstalls latest version (12.0) of azure-storage-blob
Now I have these: pip freeze adal==1.2.2 azure==4.0.0 azure-applicationinsights==0.1.0 azure-batch==4.1.3 azure-common==1.1.23 azure-core==1.0.0 azure-cosmosdb-nspkg==2.0.2 azure-cosmosdb-table==1.0.6 azure-datalake-store==0.0.48 azure-eventgrid==1.3.0 azure-graphrbac==0.40.0 azure-keyvault==1.1.0 azure-loganalytics==0.1.0 azure-mgmt==4.0.0 azure-mgmt-advisor==1.0.1 azure-mgmt-applicationinsights==0.1.1 azure-mgmt-authorization==0.50.0 azure-mgmt-batch==5.0.1 azure-mgmt-batchai==2.0.0 azure-mgmt-billing==0.2.0 azure-mgmt-cdn==3.1.0 azure-mgmt-cognitiveservices==3.0.0 azure-mgmt-commerce==1.0.1 azure-mgmt-compute==4.6.2 azure-mgmt-consumption==2.0.0 azure-mgmt-containerinstance==1.5.0 azure-mgmt-containerregistry==2.8.0 azure-mgmt-containerservice==4.4.0 azure-mgmt-cosmosdb==0.4.1 azure-mgmt-datafactory==0.6.0 azure-mgmt-datalake-analytics==0.6.0 azure-mgmt-datalake-nspkg==3.0.1 azure-mgmt-datalake-store==0.5.0 azure-mgmt-datamigration==1.0.0 azure-mgmt-devspaces==0.1.0 azure-mgmt-devtestlabs==2.2.0 azure-mgmt-dns==2.1.0 azure-mgmt-eventgrid==1.0.0 azure-mgmt-eventhub==2.6.0 azure-mgmt-hanaonazure==0.1.1 azure-mgmt-iotcentral==0.1.0 azure-mgmt-iothub==0.5.0 azure-mgmt-iothubprovisioningservices==0.2.0 azure-mgmt-keyvault==1.1.0 azure-mgmt-loganalytics==0.2.0 azure-mgmt-logic==3.0.0 azure-mgmt-machinelearningcompute==0.4.1 azure-mgmt-managementgroups==0.1.0 azure-mgmt-managementpartner==0.1.1 azure-mgmt-maps==0.1.0 azure-mgmt-marketplaceordering==0.1.0 azure-mgmt-media==1.0.0 azure-mgmt-monitor==0.5.2 azure-mgmt-msi==0.2.0 azure-mgmt-network==2.7.0 azure-mgmt-notificationhubs==2.1.0 azure-mgmt-nspkg==3.0.2 azure-mgmt-policyinsights==0.1.0 azure-mgmt-powerbiembedded==2.0.0 azure-mgmt-rdbms==1.9.0 azure-mgmt-recoveryservices==0.3.0 azure-mgmt-recoveryservicesbackup==0.3.0 azure-mgmt-redis==5.0.0 azure-mgmt-relay==0.1.0 azure-mgmt-reservations==0.2.1 azure-mgmt-resource==2.2.0 azure-mgmt-scheduler==2.0.0 azure-mgmt-search==2.1.0 azure-mgmt-servicebus==0.5.3 azure-mgmt-servicefabric==0.2.0 azure-mgmt-signalr==0.1.1 azure-mgmt-sql==0.9.1 azure-mgmt-storage==2.0.0 azure-mgmt-subscription==0.2.0 azure-mgmt-trafficmanager==0.50.0 azure-mgmt-web==0.35.0 azure-nspkg==3.0.2 azure-servicebus==0.21.1 azure-servicefabric==6.3.0.0 azure-servicemanagement-legacy==0.20.6 azure-storage-blob==1.5.0 azure-storage-common==1.4.2 azure-storage-file==1.4.0 azure-storage-queue==1.4.0 certifi==2019.9.11 cffi==1.13.2 chardet==3.0.4 cryptography==2.8 idna==2.8 isodate==0.6.0 msrest==0.6.10 msrestazure==0.6.2 oauthlib==3.1.0 pycparser==2.19 PyJWT==1.7.1 python-dateutil==2.8.1 requests==2.22.0 requests-oauthlib==1.3.0 six==1.13.0 urllib3==1.25.7
Hi @courtenayparserr probably you are using the most recent package? If the package version is 12.0.0 then try to create a new virtual environment and do: pip install azure-storage-blob==2.1.0 You will be able to import BlockBlobService
Works perfectly fine for me:
pip freeze
outputpython --version
outputI’d suggest updating to a newer version and increasing the logging verbosity for diagnosis. As @zezha-msft said, it sounds like something with your overall system setup isn’t correct…
Hi @harmonyliu to use BlockBlobService in azure-storage-blob==2.1.0 make sure you have a clean virtual environment(It’s highly recommended to create a new one) and just do
pip install azure-storage-blob==2.1.0
No extra command is needed.Let me know if it’s still not working
That didn’t work for me. Still getting this issue.
How do we move past this?
For me it was just
pip install azure-storage-blob==2.1.0
Hi @dxkaufman Thanks for reaching out. There’s no BlockBlobService in version>=12.0.0. Please see the wiki https://github.com/Azure/azure-storage-python/wiki#frequently-encountered-problem-no-module-named-azurestorageblob
To get text content of blob in v12.3.2, you should do the following thing
@SeaDude I think that solution doesn’t work anymore, I’ve tried quite a few times with every possible solution.
I need to know if anyone is able to run
BlobServiceClient
andBlockBlobService
together.Wah, I'm a ranting baby here. My apologies!
This is very confusing…
Per @lmazuel in this thread two days ago, “
azure-storage
is an incompatible old version ofazure-storage-blob
. You cannot install them at the same time, and that will create terrible conflicts.”This directly conflicts with @yashpatel7025 's “solution” above.
As outlined in the thread with @lmazuel, I could NOT install
BlobServiceClient
.azure-storage
then!pip install -U azure-storage-blob
to fix the problem.NOW, I can’t install
BlockBlobService
which exhibits nearly the same error as I had withBlobServiceClient
from the other day!I’m trying to use the elegant code found here to directly download large binary files from the web straight to a blob.
I’m using Azure Notebooks and Azure Databricks so no, I can’t complicate things with using
venv's
. These are basically hosted Jupyter notebooks without access to the OS which hosts them.!pip freeze
azure packages:!pip install azure
saying something to the effect of “After vX.0 ofazure
, downloading all packages at once is deprecated. Please download packages individually”, we really need these dependencies fixed.this worked for me when I was dealing with BlockBlobService import issues
This works for me
pip install azure-storage --upgrade pip install azure-storage-blob --upgrade pip install azure --upgrade
after this pip freeze gives
azure==4.0.0 azure-storage==0.36.0 azure-storage-blob==1.5.0
now I am able to run following from azure.storage.blob import BlockBlobService, PublicAccess
Your code might still be using the legacy Python BlobSDK (https://docs.microsoft.com/en-us/azure/storage/blobs/storage-quickstart-blobs-python-legacy) But you might have update the library to the latest version. Use this SDK now to update your code https://docs.microsoft.com/en-us/azure/storage/blobs/storage-quickstart-blobs-python
you are a legend, worked for me. thanks!
@xiafu-msft,
Thank you for the example of how to use
BlobServiceClient
to get aBlobClient
. I now see this option listed in the SDK docs here.An alternative is to instantiate a separate
BlobClient
using a SAS. Not sure if its any easier, but the way I did it was:Hi @xiafu-msft Thanks for the quick response. I was starting to get that idea, although I was looking at SDK documentation that seemed to indicate it was still part of the model. I think the docs aren’t super clear about what version they relate to.
I appreciate the sample. All the samples I was looking at last night seem to create a container before accessing it, even when the description is just for reading a blob. I found that a little confusing, though I surmised that the assumption was that the container didn’t exist yet, and your example seems to make that clearer.
Dylan
@vipulgupta2048 I just left the old version (v2.1) altogether and implemented everything on (v12.0) 😃