How to open IPython Notebook file

The .ipynb file is an IPython Notebook file containing the Python commands, output and notes that another user has recorded.

To be able to create or open this file, we need to install IPython and its notebook package:

$ sudo apt install ipython-notebook

After installation, it is invoked as:

$ ipython notebook

This open a Mathematica-like web interface in your browser. You can create new IPython Notebook files or open existing files for viewing.

On a recent IPython Notebook file, I got this error when I opened it:

Error loading notebook
Unreadable Notebook: Unsupported JSON nbformat version 4 (supported version: 3)

This means that a more recent version of notebook package needs to be used to open this file. More confusingly, the notebook package has been moved into a new project called Jupyter. Since this is a new development its package was not available on my ancient Ubuntu.

I installed it from PyPI using:

$ sudo pip3 install jupyter

To open its notebook web interface:

$ jupyter-notebook

I was able to open the problematic IPython Notebook file correctly using this.

Tried with: Jupyter 4.x and Ubuntu 14.04

Advertisements

IPython Notebook error: Unsupported JSON nbformat

20150701_ipython_error

Problem

I ran the IPython Notebook server in a directory containing a .ipynb notebook file:

$ ipython notebook

It opened the URL http://127.0.0.1:8888 in my browser. The notebook file was listed in the webpage. I clicked it to load it and got this error:

Error loading notebook

Unreadable Notebook: Unsupported JSON
nbformat version 4 (supported version: 3)

Solution

This error is caused due to opening a notebook created with a newer IPython on a computer with an older IPython. On my computer, I was using IPython installed from Ubuntu repositories, which is ancient.

I first uninstalled it:

$ sudo apt remove ipython

I installed the latest IPython from the Python Package Index:

$ sudo pip install ipython

The installation was successful, but on running IPython it complained about many other programs. I installed the libraries it complained about:

$ sudo apt install python-zmq python-jinja2 python-jsonschema

IPython Notebook ran correctly and I was able to open the notebook after this! πŸ™‚

Tried with: IPython 3.2 and Ubuntu 14.04

Python: pkg_resources module error

Problem

Run ipython3.exe and it quits with this error: ImportError: No module named pkg_resources

Solution

pkg_resources is a module that ships with the setuptools package. setuptools has been adandoned now, but a fork of it named distribute provides this module. So, install distribute (see how) and this error will be gone.

Tried with: ipython 0.12.1, Python 3.2 64-bit and Windows 7 64-bit