如何查询Azure Notebook的Python SDK版本及解决Blob导入错误
Hey there! Let's work through your Azure Storage Blob SDK issues step by step.
How to Check Your Azure Storage SDK Version
To confirm exactly which versions of the Azure Storage libraries are running in your Azure Notebook environment, run these commands directly in a notebook cell:
Check the legacy
azure-storagepackage version:!pip show azure-storageOr verify within Python:
import azure.storage print(azure.storage.__version__)Check the modern
azure-storage-blobpackage version:!pip show azure-storage-blobOr verify within Python:
import azure.storage.blob print(azure.storage.blob.__version__)
Your hunch about version differences is totally right: the BlobServiceClient class belongs to Azure Storage Blob SDK v12+, while older versions (like v0.36.0 of azure-storage) rely on BlockBlobService instead.
Fixing the ImportError: cannot import name 'BlobServiceClient'
The core problem here is a namespace conflict between the legacy azure-storage package (v0.36.0) and the modern azure-storage-blob package (v12.3.0) you installed. These two packages overlap in their module structure, causing import confusion. Here's how to resolve it:
Uninstall conflicting packages to clean up your environment:
!pip uninstall -y azure-storage azure-storage-blobReinstall only the modern, standalone SDK:
!pip install azure-storage-blob --upgradeVerify the installation to confirm you're on v12+:
import azure.storage.blob print(azure.storage.blob.__version__)Use the correct import statement for v12+ SDK:
from azure.storage.blob import BlobServiceClient
Why didn't upgrading azureml-sdk help? The azureml-sdk often includes a dependency on the legacy azure-storage package, which would reintroduce the conflict. By explicitly uninstalling and reinstalling the standalone azure-storage-blob package, you ensure you're using the modern library structure.
If you need to work with the legacy SDK for compatibility reasons, use this import instead:
from azure.storage.blob import BlockBlobService
内容的提问来源于stack exchange,提问作者SeaDude

