jupyter nbconvert-到笔记本不排除原始单元格 [英] jupyter nbconvert --to notebook not excluding raw cells

查看:261
本文介绍了jupyter nbconvert-到笔记本不排除原始单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将笔记本从./doc文件夹导出到项目根目录中的`./notebook/文件夹,但是要删除所有我拥有rst的原始单元格.

我尝试了以下操作:

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

我正在Makefile中执行此操作(因此$<$@分别是本地笔记本的名称和一旦移动到顶级./notebook目录的笔记本的名称)

它可以运行,但是原始单元仍在笔记本副本中.有什么我想念的吗?

解决方案

似乎是由于一个错误-当输出格式为笔记本"时,nbconverts似乎是捷径,绕过了预处理器.

我在github上至少遇到了一个与此有关的问题: https://github.com/jupyter/nbconvert/issues/895

这是我的解决方法.

  1. 创建具有以下内容的自定义模板文件custom_notebook.tpl:

{% extends 'null.tpl'%}

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

这实际上是复制笔记本,但允许预处理器运行.

  1. 在命令行中,将--to notebook替换为--to custom --template=custom_notebook.tpl

结果将是运行过滤器的有效笔记本.我尚未使用--TemplateExporter.exclude_raw=True进行过测试,但是它与--TagRemovePreprocessor.remove_cell_tags一起使用时,使用--to notebook选项遭受了相同的无效效果.

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?

解决方案

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.

这篇关于jupyter nbconvert-到笔记本不排除原始单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆