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?

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.

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 -O ~/ &&
/bin/bash ~/ -b -p /opt/conda -u &&
rm ~/ &&
echo “. /opt/conda/etc/profile.d/” >> ~/.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


Error in jupyterlab:

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.


How should we add it in the kernel ?

The docker-stacks docs contain an example of adding a kernel in a new environment: