How to use a specific python conda environment in a Jupyter notebook ?

Published: March 31, 2020

DMCA.com Protection Status

Example of how to use a given python conda environment in a Jupyter notebook.

Create a conda environment

To install conda go to Anaconda Individual Edition . Since conda is installed in your system to create an environment (called for example hereafter worklab) use the following command:

conda create --name worklab

and then enter

source activate worklab

to activate the environment called worklab.

Note: to get a list of your environment, there is the command:

conda env list

that returns in my case for example:

# conda environments:
#
base                     /Users/mb/anaconda3
websitedev               /Users/mb/anaconda3/envs/websitedev
websitedev2              /Users/mb/anaconda3/envs/websitedev2
worklab               *  /Users/mb/anaconda3/envs/worklab

Use a conda environment in a Jupyter notebook

To use for example the environment worklab that we just created in a Jupyter notebook , a solution is to use ipykernel. Enter the following command:

conda install -c anaconda ipykernel

and then

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

Now run a Jupyter notebook on your local machine using:

jupyter notebook

Then, to select the conda environment. use the dropdown menu on the right (see figure below)

How to use a specific python conda environment in a Jupyter notebook ?
How to use a specific python conda environment in a Jupyter notebook ?

or go in the menu 'kernel':

How to use a specific python conda environment in a Jupyter notebook ?
How to use a specific python conda environment in a Jupyter notebook ?

References

Image

of