pythonazureazure-machine-learning-serviceazureml-python-sdk

Get an AzureML environment `source` field in python


I'm trying to get the source field of an AzureML environment using the python SDK (either version 1 or 2).
It seem like neither version 1 nor version 2 support it, although the web UI has it.

Anyone has an idea?

enter image description here


Solution

  • My Azure ML workspace environment:-

    enter image description here

    Source is a part of Azure ML Environment. You can list all the Environment either by its specific name or all the list together by using the below code and the source will be appended with the environment name in the output like below:-

    Make sure you replace your client id and client secret with your service principal that has access to your azure ml workspace.

    List entire list:-

    Code:-

    from azure.identity import  ClientSecretCredential
    
    from azure.ai.ml import  MLClient
    
      
    
    subscription_id = "<subscription-id>"
    
    resource_group = "siliconrg"
    
    workspace_name = "siliconmlws"
    
    tenant_id = "<tenant-id>"
    
    client_id = "<client-id>"
    
    client_secret = "<client-secret>"
    
      
    
    credentials = ClientSecretCredential(tenant_id=tenant_id, client_id=client_id, client_secret=client_secret)
    
      
    
    ml_client = MLClient(credentials, subscription_id, resource_group, workspace_name)
    
    envs = ml_client.environments.list()
    
    for  env  in  envs:
    
    print(env.name)
    

    Output:-

    enter image description here

    List specific environment by adding its name like below code:-

    Code:-

    from azure.identity import  ClientSecretCredential
    
    from azure.ai.ml import  MLClient
    
      
    
    subscription_id = "<subscription-id>"
    
    resource_group = "siliconrg"
    
    workspace_name = "siliconmlws"
    
    tenant_id = "<tenant-id>"
    
    client_id = "<client-id>"
    
    client_secret = "<client-secret>"
    
      
    
    credentials = ClientSecretCredential(tenant_id=tenant_id, client_id=client_id, client_secret=client_secret)
    
      
    
    ml_client = MLClient(credentials, subscription_id, resource_group, workspace_name)
    
    envs = ml_client.environments.list(name="AzureML-ACPT-pytorch-1.13-py38-cuda11.7-gpu")
    
    for  env  in  envs:
    
    print(env.name)
    

    Output:-

    enter image description here

    Reference:-

    Manage Azure Machine Learning environments with the CLI & SDK (v2) - Azure Machine Learning | Microsoft Learn