Configuring virtual environment for Jupyter notebook
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 then restart the system.
$ pip3 install jupyter
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 taking the time to read this article! I hope it offered some valuable insights. If you found it helpful, feel free to clap or share it with others.
If you have any questions or thoughts, feel free to leave a comment. You can follow me on Medium, LinkedIn, GitHub or contact me at atinesh.s@gmail.com.