How to share an IPython notebook

2012-09-27

IPython has an amazing notebook feature. Now it's possible to share these notebooks online, with embedded plots, images, formulas, HTML pages...

  1. Run notebook server:

    ipython2 notebook
    

    or, if you use matplotlib,

    ipython2 notebook --pylab inline
    

    You need to install python2-tornado to use notebooks (it's an optional IPython dependency).

  2. An app page will open.

    • Create a notebook.
    • Use it as usual. It is more or less similar to normal IPython.
  3. When ready to publish:

    • choose File -> Save in the notebook menu
    • in the directory where you run the notebook, find .ipynb file (or do File -> Download as -> IPython (.ipynb)); it is a JSON file
    • paste this JSON on http://gist.github.com/ or other pastebin service
    • go to http://nbviewer.ipython.org/ and insert Gist's URL (any public URL works)
    • et voilà!

An example:

  • https://gist.github.com/2352771 ⇒ http://nbviewer.ipython.org/2352771/

I just tried it (https://gist.github.com/3793147 ⇒ http://nbviewer.ipython.org/3793147/). It works for me with IPython 0.13.

Update 2015-10-06: Since this year, GitHub is rendering IPython/Jupyter notebooks directly (both on GitHub repository and on GitHub Gists): http://blog.jupyter.org/2015/05/07/rendering-notebooks-on-github/