How can I export the current notebook (from inside the notebook itself, using Python) to HTML (to a custom output path)?
You can do it. Use the following very simple steps:
I am using: OS: Ubuntu, Anaconda-Jupyter notebook, Python 3
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.
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
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.
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.