Exporting IPython Notebooks

A few things to know to export IPython notebooks.
  1. To export an existing notebook into a .py file, you can use the IPython magic command %notebook:
    In [1]: %notebook -f py your_notebook.ipynb
  2. To export a notebook into static html page, you can use nbconvert. To install nbconvert, you'll need a few things:
    After installing all these, I had a couple errors that I fixed/bypassed before I could make an html page out of my .ipynb file:
    • In ./converters/utils.py, I replaced the line "from IPython.nbformat.v3.nbjson import BytesEncoder" by "from IPython.nbformat.v2.nbjson import BytesEncoder". That's because IPython.nbformat.v3 did not exist in my older version of IPython. This is clearly not the best way to solve it but just a way around.
    • I was missing the fbm.css file in your_ipython_package_directory/frontend/html/notebook/static/css/
    • . I found the file online. If you do not have admin rights, put the file somewhere else and write the correct path to it in ../converters/html.py.

    The following command can then be used to convert a .ipynb file to html:
    $ ./nbconvert.py -f html your_notebook.ipynb


Popular Posts