Configuring virtual environment for Jupyter notebook

Atinesh
2 min readJan 25, 2021
Jupyter (Source)

Jupyter notebook is an open-source web application that helps in creating documents with text, code, mathematical equations, plots, etc. It can be very helpful in data visualization.

In some scenarios, you might want to use a separate virtual environment for your notebook. In Jupyter notebook we need to create a new kernel for a new environment.

Follow the below steps to create a new kernel.

Step 1: Install Jupyter if not already installed (Python 3)

$ pip3 install jupyter

Restart the system

Step 2: Create a virtual environment and activate it. Here I am using my tensorflow_gpu_env virtual environment

$ source tensorflow_gpu_env/bin/activate

Step 3: Install relevant dependencies inside virtual environment including ipykernel

(tensorflow_gpu_env) $ pip3 install ipykernel

Step 4: Create a new kernel inside the virtual environment

(tensorflow_gpu_env) $ python3 -m ipykernel install --user --name=tensorflow_gpu_env

Step 5: Run Jupyter notebook

(tensorflow_gpu_env) $ jupyter notebook

Step 6: Select your desired notebook then switch kernel to tensorflow_gpu_env kernel

Removing kernels:
If you wish to delete a specific kernel then issue the following command

$ jupyter kernelspec uninstall <kernel_name>

or

$ jupyter kernelspec remove <kernel_name>

Thank you for reading this post, If you like it then please clap and share it on Facebook, LinkedIn or Twitter so that other people get benefits from it.

You can follow me on Github, LinkedIn or contact me at atinesh.s@gmail.com

Happy Coding!

--

--