Multiple Python kernels for Jupyter Lab with Conda

Jeremy Brown
2 min readMar 2, 2019

TLDR; To run Jupyter Notebook/Lab in various Conda environments with different versions of Python, install new kernels on the command line and select them from within Jupyter.

The following assumes that you’ve already installed Anaconda with Python 3.7

If you, like me, naively create a new Conda env with a version of Python that is different from the default version and expect to be able to run Jupyter Notebooks using the new version of Python, you will most likely find that newly installed packages can not be found. For example:

» conda create --name dlwp python=3.6
» conda activate dlwp
» conda install keras
» jupyter lab

At this point, you might expect to be able to import Keras into your lab. Alas, this is not the case. InsteadModuleNotFoundError:

ModuleNotFoundError Traceback (most recent call last) <ipython-input-1–35c811b03524> in <module> 1 import numpy as np — → 2 from keras.datasets import imdb 3 from keras import models, layers ModuleNotFoundError: No module named ‘keras’

The problem here is that Jupyter does not yet have a Python 3.6 kernel installed and is defaulting to 3.7. You will need to install one for 3.6 and then select it from within Notebook/Lab. Here is how that can be accomplished:

conda install ipykernel
python -m ipykernel install --user --name dlwp --display-name="Python 3.6 Deep Learning With Python"

Now restart Jupyter Lab and select your newly installed kernel, as demonstrated in the GIF up top.

--

--

Jeremy Brown

Software Engineer, originally from the U.S. and now living and working in Vienna, Austria. I write about Programming, Music, Machine Learning & NLP