How to add conda environment to jupyter lab

Statistic Dean picture Statistic Dean · Oct 26, 2018 · Viewed 41.8k times · Source

I'm using Jupyter Lab and I'm having trouble to add conda environment. The idea is to launch Jupyter Lab from my base environment, and then to be able to choose my other conda envs as kernels.

I installed the package nb_conda_kernels which is supposed to do just that, but it's not working as I want. Indeed, let's assume I create a new Conda Environment, then I launch jupyter lab from base, I can't see the new environment as an available kernel.

I have found a "fix", which works everytime but is not convenient at all. If I install Jupyter Notebook in my new environment, then launch a jupyter notebook from this new environment, close it, go back to base environment, and then launch Jupyter Lab from base environment, my new environment is available as a kernel in Jupyter Lab.

If you know how to make it work without this "fix", I would be very grateful.

Answer

Nihal Sangeeth picture Nihal Sangeeth · Nov 29, 2018

Assuming your conda-env is named cenv, it is as simple as :

$ conda activate cenv
(cenv)$ conda install ipykernel
(cenv)$ ipython kernel install --user --name=<any_name_for_kernel>
(cenv($ conda deactivate

If you restart your jupyter notebook/lab you will be able to see the new kernel available.

PS: If you are using virtualenv etc. the above steps hold good.