Getting error "Please set the default workspace with MLClient". How do I set the default workspace with MLClient? Trying to use data asset
https://learn.microsoft.com/en-us/azure/machine-learning/how-to-create-register-data-assets?tabs=Python-SDK
from azure.ai.ml.entities import Data
from azure.ai.ml.constants import AssetTypes
from azure.ai.ml import MLClient
#Enter details of your AzureML workspace
subscription_id = "<SUBSCRIPTION_ID>"
resource_group = "<RESOURCE_GROUP>"
workspace = "<AZUREML_WORKSPACE_NAME>"
ml_client = MLClient(subscription_id, resource_group, workspace)
data_location='path'
my_data = Data(
path=data_loacation,
type=AssetTypes.URI_FOLDER,
description="Data",
name="Data_test")
ml_client.data.create_or_update(my_data)
2
Answers
Make sure you have installed
Python SDK azure-ai-ml v2(preview)
usingpip install --pre azure-ai-ml
You can try following code snippets taken from workspace.ipynb to set the default workspace with MLClient:
Import required libraries:
Creating a unique workspace name with current datetime to avoid conflicts:
Get a list of workspaces in a resource group:
Load a specific workspace using parameters:
I recommend to replace
<SUBSCRIPTION_ID>
,<RESOURCE_GROUP>
and<AZUREML_WORKSPACE_NAME>
with actual values.If you do that, the MLClient constructor will set the workspace accordingly.