Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save victorkristof/df75a0ff1788795759f7 to your computer and use it in GitHub Desktop.
Save victorkristof/df75a0ff1788795759f7 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment