close

How to add conda environment to jupyter lab

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How to add conda environment to jupyter lab in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

HHow to add conda environment to jupyter lab?

  1. How to add conda environment to jupyter lab?

    If you restart your jupyter notebook/lab you will be able to see the new kernel available. For newer versions of jupyter kernel will appear without restarting the instance. Just refresh by pressing F5.

  2. add conda environment to jupyter lab

    If you restart your jupyter notebook/lab you will be able to see the new kernel available. For newer versions of jupyter kernel will appear without restarting the instance. Just refresh by pressing F5.

Method 1

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

$ conda activate cenv           # . ./cenv/bin/activate in case of virtualenv
(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. For newer versions of jupyter kernel will appear without restarting the instance. Just refresh by pressing F5.

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

Method 2

A solution using nb_conda_kernels. First, install it in your base environment :

(base)$ conda install -c conda-forge nb_conda_kernels

Then in order to get a kernel for the conda_env cenv :

$ conda activate cenv
(cenv)$ conda install ipykernel
(cenv)$ conda deactivate

You will get a new kernel named Python [conda env:cenv] in your next run of jupyter lab / jupyter notebook

Note : If you have installed nb_conda_kernels, and want to create a new conda environment and have it accessible right away then

conda create -n new_env_name ipykernel

will do the job.

Summery

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read