pola-rs/polars · error · ImportError
azure-identity must be installed to use…
Error message
azure-identity must be installed to use `CredentialProviderAzure`
What it means
CredentialProviderAzure depends on the azure-identity package. _ensure_module_availability checks for azure.identity at construction and raises ImportError if it is missing, giving an actionable message instead of a later import crash.
Solutions
- pip install azure-identity.
- Install the polars cloud extra, e.g. pip install 'polars[azure]'.
- Supply an Azure storage account key via a permitted config path so the identity package isn't needed.
Example fix
// before provider = pl.CredentialProviderAzure() // after # pip install azure-identity provider = pl.CredentialProviderAzure()
Defensive patterns
Strategy: try-catch
Validate before calling
import importlib.util
if importlib.util.find_spec('azure.identity') is None:
raise RuntimeError('install azure-identity before using CredentialProviderAzure') Type guard
def azure_identity_available() -> bool:
return importlib.util.find_spec('azure.identity') is not None Try / catch
try:
provider = pl.CredentialProviderAzure()
except ImportError as e:
if 'azure-identity must be installed' in str(e):
provider = None # fall back to account key / connection string auth
else:
raise Prevention
- Add azure-identity (or 'polars[azure]') to requirements for Azure workloads.
- Verify provider dependencies in a startup health check.
- Keep docker images and CI environments consistent with the extras declared in pyproject.
When it happens
Trigger: Using credential_provider='azure' or instantiating CredentialProviderAzure without azure-identity installed (and without an account key available from another permitted source).
Common situations: Bare polars install in a slim docker image; forgetting the Azure extra when setting up a new service; environments where only account-key auth was previously used.
Understand the failure class
Background: "X is not installed. Please install it with pip install Y": missing optional dependency errors — ImportError/ValueError raised when a library's optional extra was never installed — this error's family across 22 libraries.
Related errors
- the provided `credential` object
- boto3 must be installed to use `CredentialProviderAWS`
- cannot load requested aws_profile
- cannot use credential_provider when passing a DeltaTable…
- cannot use credential_provider when passing a DeltaTable…
AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18).
Data as JSON: /api/errors/ff7a561cd0ee177c.
Report an issue: GitHub.
Appendix: source
Thrown at py-polars/src/polars/io/cloud/credential_provider/_providers.py:457
if verbose:
eprint(
"[CredentialProviderAzure]: Retrieved account key from Azure CLI"
)
except Exception as e:
if verbose:
eprint(
f"[CredentialProviderAzure]: Could not retrieve account key from Azure CLI: {e}"
)
else:
return creds, None
return None
@classmethod
def _ensure_module_availability(cls) -> None:
if importlib.util.find_spec("azure.identity") is None:
msg = "azure-identity must be installed to use `CredentialProviderAzure`"
raise ImportError(msg)
@staticmethod
def _extract_adls_uri_storage_account(uri: str) -> str | None:
# "abfss://{CONTAINER}@{STORAGE_ACCOUNT}.dfs.core.windows.net/"
# ^^^^^^^^^^^^^^^^^
try:
return (
uri.split("://", 1)[1]
.split("/", 1)[0]
.split("@", 1)[1]
.split(".dfs.core.windows.net", 1)[0]
)
except IndexError:
return None
@classmethod
def _get_azure_storage_account_key_az_cli(cls, account_name: str) -> str:View on GitHub (pinned to fe841f959e)