37

What is the best way to get an ipython notebook into html format for use in a blog post?

It is easy to turn an ipython notebook into a PDF, but I'd rather publish as an html notebook.

I've found that if I download the notebook as a .ipynb file, then load it onto gist, then look at it with the ipython notebook viewer (nbviewer.ipython.org), THEN grab the html source, I can paste it into a blog post (or just load it as html anywhere) and it looks about right. However, if I use the "print view" option directly from ipython, the source contains a bunch of javascript rather than the processed html, which is not useful since the images and text are not directly included.

The %pastebin magic is also not particularly helpful for this task, since it pastes the python code and not the ipython notebook formatted code.

EDIT: Note that this is under development; see the comments under the accepted answer.

EDIT May 2 2014: As per Nathaniel's comment, a new answer is needed for ipython 2.0

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
keflavich
  • 18,278
  • 20
  • 86
  • 118
  • Change made. There is probably an answer hidden in Damian Avila's blog: http://www.damian.oquanta.info/posts/deploy-your-nikola-powered-blog-content-from-the-ipython-notebook.html – keflavich May 02 '14 at 07:32

5 Answers5

17

The right way is described in: http://blog.fperez.org/2012/09/blogging-with-ipython-notebook.html. Then you can do nbconvert -f blogger-html your_notebook.ipynb to get the html code for your post.

Daniel
  • 26,899
  • 12
  • 60
  • 88
  • 1
    nbconvert got moved to the IPython repo https://github.com/ipython/ipython/tree/master/IPython/nbconvert – Tim Swast Jul 11 '13 at 20:28
  • And now it's part of the official ipython 1.0 release. – Mike Sep 09 '13 at 21:28
  • 4
    The correct usage is `ipython nbconvert --to html IPyNotebookTestBlogPost.ipynb` in the dev version (v2.0) – keflavich Sep 21 '13 at 23:06
  • 5
    This answer is sadly out of date. As far as I can tell, there is no longer any option corresponding to the `-f blogger-html` used in that post. The `--to html` option spits out everything including all the load/save buttons at the top of the page, and it does't appear to generate header code to put in the blogger template. If there's a way to get it to work with blogger it's not documented, and I can't figure it out. – N. Virgo May 02 '14 at 06:41
11

One step further from the answer above. To create a PDF file,

  1. create a tex file

    nbconvert -f latex your_notebook.ipynb
    
  2. convert tex to pdf :

    pdflatex your_notebook.tex
    
Chillar Anand
  • 27,936
  • 9
  • 119
  • 136
Tooblippe
  • 3,433
  • 3
  • 17
  • 25
8

All the above answers seems outdated. Here is the most modern solution taken from the official nbconvertdocs.

$ jupyter nbconvert --to FORMAT notebook.ipynb

The default output format is html, for which the --to argument may be omitted:

$ jupyter nbconvert notebook.ipynb

Darshan Chaudhary
  • 2,093
  • 3
  • 23
  • 42
2

Click on file > Download > html

Gajendra D Ambi
  • 3,832
  • 26
  • 30
1

You generate the html from cmd, with your Jupyter Notebook open:

As https://stackoverflow.com/a/47773252/15117772 answered a similar question:

Also pass the --execute flag to generate the output cells

jupyter nbconvert --execute --to html notebook.ipynb

jupyter nbconvert --execute --to pdf notebook.ipynb