{"id":8871,"library":"azureml-defaults","title":"Azure ML Defaults","description":"azureml-defaults is a metapackage provided by Microsoft Azure Machine Learning. It simplifies the installation of the Azure ML SDK by pulling in a curated set of `azureml-*` packages (like `azureml-core`, `azureml-data`, `azureml-train`) at compatible versions. Its primary purpose is to ensure users have a consistent and working environment for developing Azure ML solutions. The current version is 1.62.0, and updates typically align with the broader Azure ML SDK release cycle.","status":"active","version":"1.62.0","language":"en","source_language":"en","source_url":"https://github.com/Azure/azureml-sdk-for-python","tags":["azure","machine-learning","cloud","sdk","metapackage"],"install":[{"cmd":"pip install azureml-defaults","lang":"bash","label":"Install the default Azure ML SDK"}],"dependencies":[{"reason":"Core functionality for managing workspaces, experiments, and runs. Installed by defaults.","package":"azureml-core","optional":false},{"reason":"Includes training tools and estimators. Installed by defaults.","package":"azureml-train","optional":false},{"reason":"Data management and datasets. Installed by defaults.","package":"azureml-data","optional":false}],"imports":[{"note":"azureml-defaults is a metapackage; user-facing classes are in sub-packages like azureml.core.","wrong":"from azureml_defaults import Workspace","symbol":"Workspace","correct":"from azureml.core import Workspace"},{"note":"azureml-defaults is a metapackage; user-facing classes are in sub-packages like azureml.core.","wrong":"from azureml_defaults import Experiment","symbol":"Experiment","correct":"from azureml.core import Experiment"},{"note":"Used to get the current experiment run context, especially within Azure ML compute targets.","symbol":"Run","correct":"from azureml.core import Run"}],"quickstart":{"code":"import os\nfrom azureml.core import Workspace, Experiment, Environment\n\n# NOTE: For local execution, ensure you have a config.json or environment variables.\n# You can create a config.json by connecting to your workspace in Azure portal\n# and downloading the config.json file.\n\n# Example for connecting to an existing workspace\ntry:\n    ws = Workspace.from_config() # Looks for config.json in current directory or parent directories\n    print(f\"Workspace name: {ws.name}, Resource Group: {ws.resource_group}, Location: {ws.location}\")\n\n    # Create a simple experiment\n    exp = Experiment(workspace=ws, name=\"my-first-azureml-experiment\")\n    print(f\"Experiment name: {exp.name}\")\n\n    # Start a run (this example won't submit to a remote compute, just demonstrates API)\n    with exp.start_logging() as run:\n        run.log('hello_world', 'true')\n        print(\"Run logged 'hello_world'\")\n        print(f\"Run ID: {run.id}\")\n\nexcept Exception as e:\n    print(f\"Error connecting to workspace or running experiment: {e}\")\n    print(\"Please ensure you are authenticated (e.g., 'az login') or have a valid config.json.\")\n    print(\"You might need to set AZUREML_CR_NAME, AZUREML_CR_RESOURCE_GROUP, AZUREML_CR_SUBSCRIPTION_ID in environment variables.\")\n\n# Example of creating a workspace (requires Azure CLI login and permissions)\n# from azureml.core.authentication import AzureCliAuthentication\n# try:\n#     cli_auth = AzureCliAuthentication()\n#     ws = Workspace.create(\n#         name='myworkspacename',\n#         subscription_id=os.environ.get('AZURE_SUBSCRIPTION_ID', 'YOUR_SUB_ID'),\n#         resource_group='myresourcegroup',\n#         create_resource_group=True,\n#         location='eastus',\n#         auth=cli_auth\n#     )\n#     print(f\"Created workspace: {ws.name}\")\n# except Exception as e:\n#     print(f\"Could not create workspace: {e}\")\n","lang":"python","description":"This quickstart demonstrates how to connect to an existing Azure Machine Learning Workspace and initiate a simple experiment run using the `azureml.core` components that `azureml-defaults` ensures are installed. It highlights the importance of authentication and workspace configuration (via `config.json` or environment variables) for local development."},"warnings":[{"fix":"Always import classes from their specific sub-package (e.g., `from azureml.core import Workspace`), not from `azureml_defaults`.","message":"azureml-defaults is a metapackage; it doesn't contain user-facing classes directly. Users should import from specific sub-packages like `azureml.core`, `azureml.data`, etc. Its role is to ensure these sub-packages are installed at compatible versions.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Prefer installing *only* `azureml-defaults` or *only* specific `azureml-*` packages but not both, unless you carefully manage versions. Use a clean virtual environment for each project or to test upgrades.","message":"Mixing `pip install azureml-defaults` with individual `pip install azureml-<package-name>` commands, especially across different versions, can lead to dependency conflicts or unexpected behavior. The `azureml-defaults` package pins versions for consistency.","severity":"breaking","affected_versions":"All versions, especially when upgrading or installing in existing environments."},{"fix":"If you only need a specific subset of the SDK (e.g., just `azureml-core` for deployment), consider installing only those specific packages rather than the entire `azureml-defaults` metapackage. However, be mindful of potential version conflicts.","message":"Installing `azureml-defaults` can be quite large, pulling in many dependencies. This can consume significant disk space and lead to slower environment creation, especially in constrained environments or CI/CD pipelines.","severity":"gotcha","affected_versions":"All versions"},{"fix":"For local development, ensure `az login` is performed or a `config.json` is present. For automated environments, use `ServicePrincipalAuthentication` or `ManagedIdentityAuthentication`.","message":"Authentication mechanisms for local development (`Workspace.from_config()`) often require `config.json` or prior `az login`. In compute targets, authentication is typically handled automatically through managed identity or service principal.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"`pip install azureml-defaults` or `pip install azureml-core`","cause":"The `azureml-core` package (or the `azureml-defaults` metapackage which includes it) is not installed in the current Python environment.","error":"ModuleNotFoundError: No module named 'azureml.core'"},{"fix":"Run `az login` in your terminal, or download `config.json` from your Azure ML workspace (Azure Portal -> Overview -> Download config.json) and place it in your script's directory or a parent directory.","cause":"The Azure ML SDK failed to find valid credentials to connect to your workspace. This often happens locally if you haven't logged in via Azure CLI or provided a `config.json`.","error":"azureml.core.authentication.AuthenticationException: No authentication mechanisms are currently available."},{"fix":"If in a conda environment, try `conda uninstall azureml-core`. If you need to force-install a specific version, use `pip install azureml-core==X.Y.Z --ignore-installed` (use with caution as it can break dependencies) or preferably, use a fresh virtual environment.","cause":"This error often occurs in environments where `azureml-core` (or other `azureml-*` packages) were installed outside of `pip`'s normal tracking, or when `pip` tries to downgrade a package installed by `conda` or another method.","error":"Cannot uninstall 'azureml-core'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would be needed for a full uninstall."},{"fix":"Ensure your script is submitted as part of an Azure ML experiment run (e.g., via `ScriptRunConfig` or `Estimator`). For local testing, mock the `Run` object or handle the `None` case explicitly.","cause":"This typically happens when trying to access `Run.get_context()` outside of an active Azure ML experiment run. `Run.get_context()` returns `None` if not called within a submitted script on an Azure ML compute.","error":"AttributeError: 'NoneType' object has no attribute 'get'"}]}