azure-machine-learning-service

Running JupyterLab in AzureML Studio with a custom environment?


We have successfully created a custom environment "pangeo" in Azure ML Studio by clicking the "environments" tab and using the GUI to create a custom conda environment:
enter image description here

There used to be an option in the compute instance creation GUI to select an environment, but this went away a few weeks ago (at least on our Azure ML Studio instance).

My question is: How can we use this custom environment to run notebooks in Jupyerlab on an Azure ML compute instance?

(Note: I do know how to log into the compute instance and create a custom kernel using this approach, but I'd like to just use the environment I already created for each compute instance I start)


Solution

  • You don't have option to select environment directly but you can give the custom script as creation and startup script.

    Creation script will run once while creating instance and startup script runs whenever the instance is started.

    While creating the compute instance in Applications tab you will find the option like below.

    enter image description here

    Below is the sample script for setting up custom conda environment.

    #!/bin/bash
     
    set -e
    
    # This script creates a custom conda environment and kernel based on a sample yml file.
    
    source /anaconda/etc/profile.d/conda.sh
    conda env create -f env.yml
    echo "Activating new conda environment"
    conda activate envname
    conda install -y ipykernel
    sudo -u azureuser -i <<'EOF'
    echo "Installing kernel"
    source /anaconda/etc/profile.d/conda.sh
    conda activate envname
    python -m ipykernel install --user --name envname --display-name "mykernel"
    echo "Conda environment setup successfully."
    EOF
    

    Some examples what you can do.

    You can also check these sample scripts.