What to do when you want to combine jupyter notebooks and virtual environments?
The wrapper is installed
using pip
:
pip install virtualenvwrapper
The configuration is done by setting up the environment directory and
sourcing virtualenvwrapper.sh
:
export WORKON_HOME=~/Envs
mkdir -p $WORKON_HOME
source /usr/local/bin/virtualenvwrapper.sh
The previous export and source commands can be added in the .bashrc
file so that they are executed automatically.
Note that the python version used in the virtualenv is specified using the --python
option:
mkvirtualenv --python=/usr/local/bin/python3.6 3Dplot
The instructions are found in the ipython documentation.
Both the environment and the display names (visible in the notebook interface) can be specified:
pip install ipykernel
python -m ipykernel install --user --name 3Dplot --display-name "3D plotting"
jupyter-notebook
When you create a new notebook, a drop-down allows you to select the kernel or virtualenv of your choice.
From an existing notebook window, you can also modify the kernel by clicking on Kernel / Change kernel
.