Add a conda environment
This page describes how to add a conda environment to your Vertex AI Workbench instance.
Overview
When you add a conda environment to your Vertex AI Workbench instance, it appears as a kernel in your instance's JupyterLab interface.
You might add a conda environment to your Vertex AI Workbench instance to use kernels that aren't available in Vertex AI Workbench instances. For example, you can add conda environments for R and Apache Beam. Or you can add conda environments for specific older versions of the available frameworks, such as TensorFlow, PyTorch, or Python.
Before you begin
If you haven't already, create a Vertex AI Workbench instance.
Open JupyterLab
In the Google Cloud console, go to the Instances page.
Next to your Vertex AI Workbench instance's name, click Open JupyterLab.
Your Vertex AI Workbench instance opens JupyterLab.
Add a conda environment
You can add a conda environment by entering commands in your instance's JupyterLab terminal.
In JupyterLab, select File > New > Terminal.
In the Terminal window, enter the following commands:
# Creates a conda environment. conda create -n CONDA_ENVIRONMENT_NAME -y conda activate CONDA_ENVIRONMENT_NAME # Install packages using a pip local to the conda environment. conda install pip pip install PACKAGE # Adds the conda kernel. DL_ANACONDA_ENV_HOME="${DL_ANACONDA_HOME}/envs/CONDA_ENVIRONMENT_NAME" python -m ipykernel install --prefix "${DL_ANACONDA_ENV_HOME}" --name CONDA_ENVIRONMENT_NAME --display-name KERNEL_DISPLAY_NAME
Replace the following:
CONDA_ENVIRONMENT_NAME
: your choice of name for the environmentPACKAGE
: the package that you want to installKERNEL_DISPLAY_NAME
: the display name for the tile of the kernel in the JupyterLab interface
A default kernel can be created when installing to a given conda environment. You can remove the default kernel with the following command:
rm -rf "/opt/micromamba/envs/CONDA_ENVIRONMENT_NAME/share/jupyter/kernels/python3
To see your new kernel, do the following:
Refresh the page.
Select File > New Launcher.
The kernel is listed among the others in the Launcher window.
By default, conda might use pip packages in the system pip
folder
(for example, /usr/bin/pip
). Running conda install pip
ensures that
the setup uses a pip local to the environment.
Example installation: R Essentials
The following example installs R Essentials in a conda environment named r
.
conda create -n r conda activate r conda install -c r r-essentials
Example installation: pip package
The following example installs pip packages from a requirements.txt
file.
conda create -n myenv conda activate myenv conda install pip pip install -r requirements.txt DL_ANACONDA_ENV_HOME="${DL_ANACONDA_HOME}/envs/myenv" python -m ipykernel install --prefix "${DL_ANACONDA_ENV_HOME}" --name myenv --display-name myenv
Troubleshoot
To diagnose and resolve issues related to adding a conda environment, see Troubleshooting Vertex AI Workbench.
What's next
Learn more about conda.
To modify your conda environment, see Manage your conda environment.