fabiopedrosa
fabiopedrosa

Reputation: 2581

How to export current notebook in HTML on Jupyter

How can I export the current notebook (from inside the notebook itself, using Python) to HTML (to a custom output path)?

Upvotes: 41

Views: 82407

Answers (4)

code_conundrum
code_conundrum

Reputation: 599

The above answer yields the result .ipynb to .html. But it exports .html file without output. In addition, if you want .html file with output, please use also --execute.

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

Upvotes: 4

Rômulo Amaral
Rômulo Amaral

Reputation: 71

Actually you need to save your notebook first, then you can use the nbconvert command

It would be something like:

%%javascript
IPython.notebook.save_notebook()

And Then

import os
os.system('jupyter nbconvert --to html yourNotebook.ipynb')

If you do not do this, it will not convert the actual notebook.

Upvotes: 7

Yogesh Awdhut Gadade
Yogesh Awdhut Gadade

Reputation: 2708

You can do it. Use the following very simple steps:

I am using: OS: Ubuntu, Anaconda-Jupyter notebook, Python 3

1 Save your Notebook in HTML format:

  1. Start the jupyter notebook that you want to save in HTML format. First save the notebook properly so that HTML file will have a latest saved version of your code/notebook.

  2. Run the following command from the notebook itself:

    !jupyter nbconvert --to html your_notebook_name.ipynb

Edit: or you can also use: !jupyter nbconvert your_notebook_name.ipynb --to html

After execution will create HTML version of your notebook and will save it in the current working directory. You will see one html file will be added into the current directory with your_notebook_name.html name

(your_notebook_name.ipynb --> your_notebook_name.html).

If you want to know how to save it into pdf format please check my answer on this question as well: IPython notebook - unable to export to pdf

Upvotes: 18

dot.Py
dot.Py

Reputation: 5147

By looking at nbconvert docs, you'll see that you can use --to html method:

import os

os.system('jupyter nbconvert --to html yourNotebook.ipynb')

This will create a yourNotebook.html file inside yourNotebook.ipynb folder.

Upvotes: 39

Related Questions