Add conda environment to Jupyter notebook

Tzung-Chien Hsieh
2 min readSep 22, 2021

--

In this article, I will introduce how to add the conda environment to the Jupyter notebook. In the following steps, I consider Jupyter Lab and Jupyter notebook as interchangeable. I will use Jupyter Lab as an example. If you already have the environment ready to use, please directly go to Step 3 and Step 4.

Step 1: Create a new environment

Create the new environment with python version 3.8 by the command below. Here, I create an environment called “test”. If you would like to use any other python version, you could simply change it to python=3.x (the version you prefer).

conda create --name test python=3.8
Create new environment

Step 2: Activate the environment

Activate your environment by the command below. If you use a different name for the environment, please remember to change the name here from test to the name you used.

conda activate test
Activate environment

Step 3: Install ipykernel or Jupyter lab

Install ipykernel by the following command. Without this, you won’t be able to run the next step to add the environment.

conda install -c anaconda ipykernel

If you haven’t installed Jupyter lab yet, you could install Jupyter lab by the following command.

conda install jupyterlab

Step 4: Add environment to Jupyter

python -m ipykernel install --user --name=test

Step 5: Run Jupyter lab and select your environment

When you run Jupyter lab, you will then see the new environment in the Kernel list. In our example, the new environment is “test”.

Now you will be able to use the conda environment in Jupyter notebook.

--

--

Tzung-Chien Hsieh
Tzung-Chien Hsieh

Written by Tzung-Chien Hsieh

PhD in Computer Science, I will share what I learned in Programming, Machine Learning, and Rare Disorders.

No responses yet