Converting ipython notebook to html with separate images

Ben

I have an ipython notebook with a mixture of SVG and PNG graphs. I can export it to html without any trouble, but it embeds the images as encoded text in the body of the .html file.

I'm calling:

ipython nbconvert --to html mynotebook.ipynb

The output at the command line includes:

[NbConvertApp] Converting notebook mynotebook.ipynb to html
[NbConvertApp] Support files will be in mynotebook_files/

but no such directory is created, and there are no files in it.

There are related posts (1 ,2 ,3 ,4 ) but they either don't fix this specific issue, or refer to the olden days when NBconvert was a separate library.

This document explains how to solve this problem on the old way of doing things too.

I've tried to use:

ipython nbconvert --config mycfg.py

With

c = get_config()
c.NbConvertApp.notebooks = ["mynotebook.ipynb"]

in the .py file, but that's as fas as I've got.

What I'm looking for is a way to make the png files, and preferably the svg files, go into a folder. Ideally as easily as possible!

Ben

Thanks to Thomas K's nudge I've had some success in getting this to work. Consider this a proto-answer until I have a chance to get my head around all the nuances of the problem. There will probably be errors, but this is my understanding of what's happening.

To override the default behaviour of the default ipython nbconvert --to html mynotebook.ipynb command you need to specify a configuration file and call it like this ipython nbconvert --config mycfg.py. Where mycfg.py is a file in the same directory as your notebooks. Mine looks like this:

c = get_config()
c.NbConvertApp.notebooks = ["mynotebook.ipynb"]
c.NbConvertApp.export_format = 'html'
c.Exporter.preprocessors = ['extractoutput.ExtractOutputPreprocessor']

Where ["mynotebook.ipynb"] is the file, or list of files, that I want to convert. The part that controls how the notebook gets converted is 'extractoutput.ExtractOutputPreprocessor' in this case.

extractoutput.ExtractOutputPreprocessor refers to extractoutput.py, which is also in the same directory as the notebooks (although I don't think it needs to be).

extractoutput.ExtractOutputPreprocessor refers to a function in extractoutput.py that specifies how the output will be processed.

In my case the content of this file is taken exactly from the IPython repo with a small modification. Line 22 (from .base import Preprocessor) produces a

ValueError: Attempted relative import in non-package

error because it doesn't know where to look for the package. When changed to

fromIPython.nbconvert.preprocessors.base import Preprocessor

then it works and all the image assets are put into the mynotebook_files directory.

I didn't need to edit the HTML output template in this case, it knew where to look anyway.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Converting to (not from) ipython Notebook format

From Dev

Execute another ipython notebook in a separate namespace

From Dev

Jupyter (IPython) notebook: Convert an HTML notebook to ipynb

From Dev

Import html to ipython notebook file

From Java

Display multiple images in one IPython Notebook cell?

From Dev

ipython notebook read multiple images and display in CELL

From Dev

ipython notebook read multiple images and display in CELL

From Dev

How to get landscape orientation when converting IPython notebook to PDF?

From Dev

CSS Styling of HTML in IPython Notebook output

From Dev

Python dictionary as html table in ipython notebook

From Dev

Displaying an HTML file with a JS inside an iPython notebook

From Dev

igraph plot function does not show images in an IPython notebook

From Dev

Ipython notebook: show for-loop images "realtime", before next step

From Dev

igraph plot function does not show images in an IPython notebook

From Dev

Printing 2 Python Pandas DataFrame in HTML Tables in iPython Notebook

From Dev

IPython Notebook & Pandas: How does pandas produce html table?

From Dev

How to *not* display 'NaN' in ipython notebook (html table of pandas dataframe)?

From Dev

IPython Notebook: How to combine HTML output and matplotlib figures?

From Dev

How to set the <title> tag for IPython notebook HTML output?

From Dev

How to convert an ipython notebook to html with collapsed output (and/or input)

From Dev

How do I separate slides when exporting an IPython notebook to reveal.js?

From Dev

Default notebook directory in iPython Notebook - iPython 3.0.0

From Dev

Open 'ipython notebook' as: IPython notebook vs Jupyter

From Dev

Ipython notebook link to external notebook

From Dev

Including a notebook in another notebook in IPython?

From Dev

IPython Notebook - saving notebook fails

From Dev

Ipython notebook link to external notebook

From Dev

iPython 3 Notebook raising ImportError: No module named 'IPython.frontend.html'

From Dev

How do I make 2 images appear side by side in Jupyter notebook (iPython)?

Related Related

  1. 1

    Converting to (not from) ipython Notebook format

  2. 2

    Execute another ipython notebook in a separate namespace

  3. 3

    Jupyter (IPython) notebook: Convert an HTML notebook to ipynb

  4. 4

    Import html to ipython notebook file

  5. 5

    Display multiple images in one IPython Notebook cell?

  6. 6

    ipython notebook read multiple images and display in CELL

  7. 7

    ipython notebook read multiple images and display in CELL

  8. 8

    How to get landscape orientation when converting IPython notebook to PDF?

  9. 9

    CSS Styling of HTML in IPython Notebook output

  10. 10

    Python dictionary as html table in ipython notebook

  11. 11

    Displaying an HTML file with a JS inside an iPython notebook

  12. 12

    igraph plot function does not show images in an IPython notebook

  13. 13

    Ipython notebook: show for-loop images "realtime", before next step

  14. 14

    igraph plot function does not show images in an IPython notebook

  15. 15

    Printing 2 Python Pandas DataFrame in HTML Tables in iPython Notebook

  16. 16

    IPython Notebook & Pandas: How does pandas produce html table?

  17. 17

    How to *not* display 'NaN' in ipython notebook (html table of pandas dataframe)?

  18. 18

    IPython Notebook: How to combine HTML output and matplotlib figures?

  19. 19

    How to set the <title> tag for IPython notebook HTML output?

  20. 20

    How to convert an ipython notebook to html with collapsed output (and/or input)

  21. 21

    How do I separate slides when exporting an IPython notebook to reveal.js?

  22. 22

    Default notebook directory in iPython Notebook - iPython 3.0.0

  23. 23

    Open 'ipython notebook' as: IPython notebook vs Jupyter

  24. 24

    Ipython notebook link to external notebook

  25. 25

    Including a notebook in another notebook in IPython?

  26. 26

    IPython Notebook - saving notebook fails

  27. 27

    Ipython notebook link to external notebook

  28. 28

    iPython 3 Notebook raising ImportError: No module named 'IPython.frontend.html'

  29. 29

    How do I make 2 images appear side by side in Jupyter notebook (iPython)?

HotTag

Archive