ImportError: cannot import name 'BlobServiceClient' from 'azure.storage.blob'
Fixes code written for azure-storage-blob v12 that runs against the old v2 track. Use when BlobServiceClient cannot be imported. Not for v12-installed environments (then the bug is elsewhere).
TL;DR: BlobServiceClient only exists in azure-storage-blob v12+. You have the legacy 2.x track installed (it provides BlockBlobService instead). Upgrade with pip install -U azure-storage-blob and the import works.
ImportError: cannot import name 'BlobServiceClient' from 'azure.storage.blob'Fix it
- Check the version: pip show azure-storage-blob. Expected: 2.x if you hit this.
- Upgrade: pip install -U azure-storage-blob. Expected: version 12.x.
- Verify: python -c "from azure.storage.blob import BlobServiceClient; print('ok')". Expected: ok.
- Update your code to the v12 API (connection string or credential based client); v2 and v12 APIs are not interchangeable.
When this applies
- pip shows azure-storage-blob 2.x and you want the modern API.
When it doesn't
- pip already shows 12.x: then something else shadows the package (namespace conflict); check azure.path.
- You intentionally target the legacy API: keep 2.x and use BlockBlobService.
Compatibility
- azure-storage-blob >= 12.0. Python 3.8+.
Why it happens
Microsoft rebooted the storage SDK as v12 with a new object model. The 2.x track stayed on PyPI for back-compat, and old pins or tutorials keep installing it.
Edge cases
- The v12 migration guide covers renamed methods (createblobfrompath becomes uploadblob, etc.); budget time for the rewrite, not just the import.
- azure-storage (the old meta-package) pulls in 2.x; remove it.
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.