Converting ipython notebook to html with separate images
Question: 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](http://stackoverflow.com/questions/12502187/ipython-notebook-to-html-for-
blog-post?rq=1) ,[2](http://stackoverflow.com/questions/19082746/convert-
ipython-notebook-to-mediawiki)
,[3](http://stackoverflow.com/questions/20039058/blogging-with-ipython-
notebook) ,[4](http://stackoverflow.com/questions/20609114/how-to-post-
ipython-notebook-thread-into-wordpress-blog) ) but they either don't fix this
specific issue, or refer to the olden days when NBconvert was a separate
library.

[This
document](http://nbviewer.ipython.org/github/Carreau/posts/blob/master/06-NBconvert-
Doc-Draft.ipynb) 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!


Answer: Thanks to [Thomas K](http://stackoverflow.com/users/434217/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](https://github.com/ipython/ipython/blob/master/IPython/nbconvert/preprocessors/extractoutput.py)
with a small modification. Line 22 (`from .base import Preprocessor`) produces
a

`ValueError: Attempted relative import in non-package`

[error](https://www.inkling.com/read/learning-python-mark-
lutz-4th/chapter-23/package-relative-imports) because it doesn't know where to
look for the package. When changed to

`from`**`IPython.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](https://github.com/ipython/ipython/tree/master/IPython/nbconvert/templates/html)
in this case, it knew where to look anyway.

