Tuesday 23 June 2020

Add virtual environment to Jupyter notebook

Add/Remove Virtual Environment to Jupyter Notebook
========================================

1.Activate the virtual environment.


2. Install the Jupyter Core

sudo apt install jupyter-core


3.Install ipykernel which provides the IPython kernel for Jupyter


pip install --user ipykernel

4.Add your virtual environment to Jupyter by typing:

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


This should print the following:

Installed kernelspec myenv in /home/user/.local/share/jupyter/kernels/ENVNAME


The virtual environment is now added in the Jupyter Notebook


5.Launch a Jupyter Notebook and change the Kernel using the option Kernel>Change Kernel


6.To list the paths of all the listed kernels use the command
jupyter kernelspec list

7. It is also better to install jupyter notebook to the environment itself (i had to face the situation package not found when running the notebook as in step 4 and then changing the kernel). To do this activate the environment and then type in 

conda install jupyter notebook

8.To uninstall any unwanted kernel, list the paths of all the installed kernels and then uninstall using the command

jupyter kernelspec uninstall unwanted-kernel

Add Virtual Environment to Jupyter Notebook

No comments:

Post a Comment