Convert ipython laptop to html with individual images

I have an ipython laptop with a mixture of SVG and PNG graphics. I can export it to html without any problems, but it inserts images as encoded text in the body of the .html file.

I'm calling:

 ipython nbconvert --to html mynotebook.ipynb 

The output on the command line includes:

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

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

There are similar messages ( 1 , 2 , 3 , 4 ), but they either do not fix this particular problem or refer to the old days when NBconvert was a separate library.

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

I tried to use:

 ipython nbconvert --config mycfg.py 

FROM

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

in the .py file, but it's like fas, like mine.

I am looking for a way to make png files, and preferably svg files, enter a folder. Ideal as easy as possible!

+7
ipython ipython-notebook
source share
1 answer

Thanks to Thomas K pushing I had some success to get this to work. Think, this is a proto-answer until I have the opportunity to get around all the nuances of the problem. There will probably be mistakes, but this is my understanding of what is happening.

To override the default behavior of ipython nbconvert --to html mynotebook.ipynb you need to specify the configuration file and call it like this: ipython nbconvert --config mycfg.py . Where mycfg.py is a file in the same directory as your laptops. My 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. In this case, the part that controls the conversion of the laptop is 'extractoutput.ExtractOutputPreprocessor' .

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

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

In my case, the contents of this file are taken exactly from the IPython repo with a slight modification. Line 22 ( from .base import Preprocessor ) creates

ValueError: Attempted relative import in non-package

an error because he does not know where to look for a package. When changing to

from IPython.nbconvert.preprocessors .base import Preprocessor

then it works, and all image objects are placed in the mynotebook_files directory.

I did not need to edit the HTML output template in this case, he knew where to look anyway.

+4
source share

All Articles