jupyter nbconvert --to notebook not excluding raw cells

无人久伴 提交于 2019-12-11 05:41:59

问题


I'm trying to export notebooks from a ./doc folder to a `./notebook/ folder in the root of my project, but remove all the raw cells where I have rst.

I tried the following:

jupyter nbconvert --to notebook $< --output=$@ --TemplateExporter.exclude_raw=True

I'm doing this in a Makefile (so the $< and $@ are the name of the local notebooks and the name of the notebook once it is moved to the top-level ./notebook dir, respectively).

It runs, but the raw cells are still there in the copies of the notebooks. Is there something I'm missing?


回答1:


There seems to be due to a bug - when the output format is 'notebook', then nbconverts seems to take a short cut, bypassing preprocessors.

I've come across at least one more issue on github related to it: https://github.com/jupyter/nbconvert/issues/895

Here is my workaround.

  1. Create a custom template file custom_notebook.tpl with the following content:
{% extends 'null.tpl'%}

{%- block body %}
{{ nb | json_dumps }}
{% endblock body %}

This essentially copies the notebook, but allows preprocessors to run.

  1. In the command line replace --to notebook with --to custom --template=custom_notebook.tpl

The result will be a valid notebook with filters run on it. I have not tested with --TemplateExporter.exclude_raw=True but it worked with --TagRemovePreprocessor.remove_cell_tags that suffered the same null effect with --to notebook option.



来源:https://stackoverflow.com/questions/53974582/jupyter-nbconvert-to-notebook-not-excluding-raw-cells

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!