How to Add Conda Environment to Anaconda Jupyter Notebook

Dogukan Ulu
2 min readAug 8, 2023

--

In this article, we are going to create a new Conda virtual environment, install the necessary dependencies and add the environment to the Anaconda Jupyter notebook.

Assuming we already have conda installed and the conda command is in the PATH, we are going to first create our environment. We can change the environment name as we desire, we will use pyspark for this article. We can also assign a Python version to be used in this environment. We can choose one of the following.

conda create --name pyspark
conda create --name pyspark python=3.9

We can activate the environment using the following command:

conda activate pyspark

After activating the environment, we can install the necessary dependencies. You may see an example below, modify the dependencies according to your use case. We can use either pip install or conda install.

pip install pyspark
conda install -c conda-forge pyspark

We created our environment and installed the necessary dependencies so far. Now it’s time to add the virtual env to Jupyter Notebook to be able to choose while creating a new notebook. We should first install ipykernel. We can choose one of the following.

pip install ipykernel
conda install -c anaconda ipykernel

After installing ipykernel, we can add our new environment to Jupyter Notebook. We can choose one of the following.

ipython kernel instal --user --name=pyspark
python -m ipykernel install --user --name=pyspark

After running this command, we can see that our virtual environment is added to the Jupyter Notebook.

Hope it helps, thanks for reading :)

--

--