Follow these steps to create a custom environment within a Kubeflow Notebook Server. This will allow you to install python packages in separate environments, and switch between them when using notebooks.

Step 1: Create an Environment

Open a Terminal, and use conda to create a custom environment. For example, this command will create an environment named my_env and install python 3.10 along with ipykernel :

# Change this python ver as needed:
python=3.10

# Change this environment name (e.g. "trl", "pytorch-py310", etc.):
env_name=my_env

# Use conda to create the environment, and install ipykernel:
conda create --yes -p /home/jovyan/${env_name} python=${python} ipykernel

Notice we used the -p (prefix) flag to specify the location of the environment, which we use to ensure that the environment is not deleted when we stop and restart a Notebook server.

Next initialize the environment:

conda init
source ~/.bashrc
conda activate /home/jovyan/${env_name}

The output should look like this, with (/home/jovyan/YOUR_ENVIRONMENT_NAME) as part of the prompt, indicating that your shell has the new environment activated, eg:

Untitled

Step 2: Create an ipykernel:


python -m ipykernel install --user --name=${env_name}-kernel

This will create an ipykernel called YOUR_ENVIRONMENT_NAME-kernelthat you can specify in a Notebook. Since this kernel was created within the conda environment, the kernel will have access to any packages that are installed in that environment.

Step 3: Launch a Notebook

Launch a notebook and use the kernel.

Open the Launcher. The new Notebook option will appear for the new kernel: