Primal Data Advent Calendar #2: How to fix Conda environment not showing in JupyterLab
By: Katarina Benesova
Tags: Python, Jupyter Notebook, Conda

With 83% of Data Scientists using Jupyter regularly as shown by a massive Kaggle survey from 2019, it is the one tool they go to to do their work. Especially if what they are after is a one-off visual analysis.

As great as Jupyter is, it sometimes resists being friends with Conda environments, a package management system for Python and others. Particularly, a Conda environment sometimes doesn’t show up in Jupyter Notebooks or JupyterLab among the list of kernels available for a notebook. If this gives you a headache too, this short article should help to fix it.

How it used to work

In my setup, which probably is a common one, it used to work like this:

Create a Conda environment for a project, install jupyterlab and other packages you need — let’s call it my-env

and other packages you need — let’s call it Set my-env as a virtual environment for a project, e.g. as a Project Interpreter in PyCharm

as a virtual environment for a project, e.g. as a Project Interpreter in PyCharm Launch JupyterLab, e.g. by running jupyter lab from a terminal (or jupyter notebook if you don’t have JupyterLab yet)

from a terminal (or if you don’t have JupyterLab yet) See all the Conda environments you created as kernels available for the notebook on the welcome page, including my-env (of course, we’re only talking environments containing ipykernel package that comes with jupyter )

List of notebook kernels that should include your Conda environments

It should also be possible to select my-env when changing the current kernel in the top right corner.

Notebook kernel selector

Although the Anaconda docs state it should still work like this, at one point Conda stopped automatically setting up the environments as Jupyter kernels, causing the newer ones not to show up in either of those list.

The quick fix

The easiest way is to install the environment with ipykernel as you apparently have to do manually now. Run this from Anaconda Prompt and reload the notebook:

python -m ipykernel install --user --name my-env --display-name my-env

Given that you have Jupyter, you should have ipykernel already installed, but if not, here’s how.

That should do it! The fix is easy, but it might take some time to get to because one might start by ruling out there’s something wrong with the environment, the recently installed packages, new version of Jupyter, etc.

Dealing with environments

Jupyter Notebook docs have a handy What to do when things go wrong section where they state Python Environments — related problems as one of the common issues. Apparently, it can be so frustrating that people don’t hesitate to use words like “Jupyter kernel hell”:

Greetings. I’m currently in a Jupyter kernel hell. I can’t figure how to fix it. And I’m not sure whether it’s a Jupyter or conda issue, so thanks for the patience! (source)

On a side note, there is also nb_conda_kernels package that might be helpful. If you install to any environment as stated here, e.g. base , then when you’re running Jupyter from the base , you should be able to switch to any other kernel containing the ipykernel package. However, what one usually wants to do is running Jupyter from the project environment, e.g. my-env , and according to my trials, my-env wasn’t among the available kernels. All in all, you could install nb_conda_kernels to my-env (and to every new environment), but from the user perspective, running conda install nb_conda_kernels instead of the above mention fix is effectively the same.

There doesn’t seem it be a reference for the reasoning behind ditching the automatic kernel installation. Nevertheless, it turns out to be the new normal and so I hope this article made adapting to it at least a little easier.