Add multiple kernels to jupyterlab

How to add a Conda environment to the list of available kernels in Jupyter Notebook or JupyterLab in zero to jupyterhub in kubernetes setup?

1 Like

In most cases the singleuser server environment can be customised in the same way you’d customise a standalone JupyterLab environment. Since Z2JH uses containers you’d need to build a custom image with your extra kernels and configuration.

I have used the default config of jupyterhub. While the jupyterlab server gets loaded I see ‘jupyterhub/k8s-singleuser-sample’ this image gets pulled. On top of this image I build an image by installing conda and creating an env. But I see ‘conda not found’ error in the jupyterlab server. Can you confirm how to setup the conda in jupyterlab server.

Dockerfile:
RUN apt-get update &&
apt-get install -y build-essential &&
apt-get install -y wget &&
apt-get clean &&
rm -rf /var/lib/apt/lists/*

ENV CONDA_DIR /opt/conda

RUN wget --quiet https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda.sh &&
/bin/bash ~/miniconda.sh -b -p /opt/conda -u &&
rm ~/miniconda.sh &&
echo “. /opt/conda/etc/profile.d/conda.sh” >> ~/.bashrc &&
echo “conda activate base” >> ~/.bashrc &&
/opt/conda/bin/conda init &&
/opt/conda/bin/conda update -n base -c defaults conda &&
/opt/conda/bin/conda create -n myenv python=3.9

ENV PATH=$CONDA_DIR/bin:$PATH

Error in jupyterlab:

1 Like

I think it’ll be easier to use an image that already includes conda, such as GitHub - jupyter/docker-stacks: Ready-to-run Docker images containing Jupyter applications

FROM jupyter/scipy-notebook:latest

RUN conda create -n myenv3 -q
RUN source activate myenv3; pip install ipykernel; 
RUN python -m ipykernel install --user --name myenv3 --display-name "myenv3 from docker"

I used this dockerfile to create a conda environment and add it in the kernel. The conda environment is getting added in the location but it is not showing up on the kernel.

image

How should we add it in the kernel ?

The docker-stacks docs contain an example of adding a kernel in a new environment:
https://jupyter-docker-stacks.readthedocs.io/en/latest/using/recipes.html#add-a-custom-conda-environment-and-jupyter-kernel