Last Updated: July 21, 2016
·
2.315K
· vicow

IPython Notebook with multiple kernels and virtualenv

IPython Notebook with multiple kernels and virtualenv

Explanations of how to install and use IPython Notebook with a venv and multiple virtualenv (one for Python 2 and one for Python 3).

Step-by-step installation

We run step-by-step and detail all the operations. A quicker, more concise guide can be found at the end of this gist.

Create virtualenv

We create first one venv for each version of Python.
mkvirtualenv -p /path/to/python2.7 venv-name deactivate mkvirtualenv -p /path/to/python3.4 venv-name3 deactivate
Note: it is common practice to append a 3 at the end of your Python stuff that uses Python 3.

Install IPython Notebook

Install IPython Notebook in both virtualenv.
workon venv-name pip install ipython[notebook] deactivate workon venv-name3 pip3 install ipython[notebook] deactivate

Set the kernel specs

Set the kernel specs for the corresponding Python versions. More details here.
workon venv-name ipython kernelspec install-self deactivate workon venv-name3 ipython3 kernelspec install-self deactivate

Usage

You can now run ipython notebook from any of your venv. Switch the kernels in the Kernel > Change Kernel menu of your Notebook. Please note that you'll need to install the libraries you need in the right venv, depending on which kernel you use.

Concise installation

We show a quicker, more concise installation, if you know what you are doing.
mkvirtualenv -p /path/to/python2.7 venv-name pip install ipython[notebook] ipython kernelspec install-self deactivate mkvirtualenv -p /path/to/python3.4 venv-name3 pip3 install ipython[notebook] ipython3 kernelspec install-self ipython notebook