Setup Jupyterlab on conda environments

notes
jupyter
conda
My template to setup Jupyterlab and conda environments

TL;DR

In the base environment:

conda install pip ipympl jupyterlab nb_conda_kernels jupyter_contrib_nbextensions jupyterlab_widgets

Then, for each virtual environment that should be available in Jupyter:

conda create -n [env_name] python==[required python version] pip
conda activate [env_name]
conda install ipykernel ipympl ipywidgets

Breakdown

  1. As an alternative, one could install a separate Jupyter instance on each virtual environment. In my experience it is tedious and error prone. For me the approach above works best.
  2. The nb_conda_kernels extension enables access to individual virtual environments from the Jupyter instance installed in the base environent.
  3. Adding ipykernel allows the virtual environment to be accessible by Jupyter.
  4. Jupyter is always started in the base environment. Then, each individual notebook will use one of the installed environments.
  5. I also install additional packages such as jupyter_contrib_extensions and jupyterlab_widgets, which I use in most of my projects.

Resources

  • nb_conda_kernels here
  • ipykernel here
  • Post where I found out about this approach first