Install & Compatibility
Where this runs
tested against v1.34.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 9.851s · 228.8MB
glibcpy 3.10–3.910 runs
installs and imports cleanly · install 16.6s · import 9.056s · 230MB
244MB installed
● package 244MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
MLClient
✓ from azure.ai.ml import MLClient
✗ from azureml.core import Workspace
MLClient is the entry point for the v2 SDK, replacing Workspace from the v1 SDK (azureml-sdk).
DefaultAzureCredential
✓ from azure.identity import DefaultAzureCredential
✗ from azure.ai.ml.identity import DefaultAzureCredential
Authentication credentials are provided by the separate azure-identity library.
CommandJob
✓ from azure.ai.ml.entities import CommandJob
✗ from azure.ai.ml import command
Job-related entities and other assets are typically found under azure.ai.ml.entities.
Environment
✓ from azure.ai.ml.entities import Environment
Similar to jobs, resource definitions like Environment are under azure.ai.ml.entities.
This quickstart demonstrates how to connect to an Azure Machine Learning workspace using the `MLClient` and `DefaultAzureCredential`. It retrieves workspace details from environment variables (or placeholders) and then lists the custom environments registered in the workspace. Ensure `AZURE_SUBSCRIPTION_ID`, `AZURE_RESOURCE_GROUP`, and `AZURE_ML_WORKSPACE_NAME` environment variables are set, or replace placeholders with your actual values. Also, authenticate via Azure CLI (`az login`) or other methods for `DefaultAzureCredential` to work.
import os
from azure.ai.ml import MLClient
from azure.identity import DefaultAzureCredential
# Configure Azure credentials and workspace details
subscription_id = os.environ.get('AZURE_SUBSCRIPTION_ID', 'YOUR_SUBSCRIPTION_ID')
resource_group = os.environ.get('AZURE_RESOURCE_GROUP', 'YOUR_RESOURCE_GROUP')
workspace_name = os.environ.get('AZURE_ML_WORKSPACE_NAME', 'YOUR_WORKSPACE_NAME')
# Instantiate DefaultAzureCredential
try:
credential = DefaultAzureCredential()
# Check if credential works by getting a token (optional, but good for early validation)
_ = credential.get_token('https://management.azure.com/.default')
except Exception as e:
print(f"Authentication failed: {e}")
print("Please ensure you are logged in to Azure CLI, VS Code, or have appropriate environment variables set.")
exit(1)
# Create an MLClient instance
ml_client = MLClient(
credential=credential,
subscription_id=subscription_id,
resource_group_name=resource_group,
workspace_name=workspace_name
)
print(f"Connected to Azure ML workspace: {ml_client.workspace_name}")
# Example: List existing environments in the workspace
print("Listing existing environments...")
environments = ml_client.environments.list()
for env in environments:
print(f"- {env.name} (version: {env.version})")
az --version
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'azure.ai.ml'
The 'azure-ai-ml' package is not installed in the Python environment.
fixInstall the package using pip: 'pip install azure-ai-ml'.
ImportError: cannot import name 'MLClient' from 'azure.ai.ml'
The 'azure-ai-ml' package is not installed or is outdated.
fixEnsure the package is installed and up to date: 'pip install --upgrade azure-ai-ml'.
ImportError: cannot import name 'TokenCredential' from 'azure.core.credentials'
The 'azure-core' package is outdated and lacks the 'TokenCredential' class.
fixUpgrade the 'azure-core' package: 'pip install --upgrade azure-core'.
ImportError: cannot import name 'INSTRUMENTATION_KEY' from 'azure.ai.ml._telemetry.logging_handler'
The 'INSTRUMENTATION_KEY' attribute has been removed or renamed in recent versions of 'azure-ai-ml'.
fixUpdate the code to remove or replace references to 'INSTRUMENTATION_KEY'.
ImportError: cannot import name 'PromptAgentDefinition' from 'azure.ai.projects.models'
The 'PromptAgentDefinition' class is not present in the installed version of 'azure-ai-projects'.
fixVerify the documentation for the correct import or update the package to the latest version.
Upgrade
Version history
1.34.1latest on PyPI · released Jul 14, 2026
Audit
Dependencies
azure-identityrequiredRequired for authentication with Azure services, especially for `DefaultAzureCredential`.