jupyter nbconvert:如何在不执行多次的情况下执行和输出多种格式?

jupyter nbconvert: How to execute and output multiple format without execute multiple time?

我正在使用 nbconvert

从SimpleNotebook.ipynb,我想输出两个文件:

我完成这项工作的命令行:

jupyter nbconvert SimpleNotebook.ipynb --to notebook --execute 
jupyter nbconvert SimpleNotebook.ipynb --to html --execute --no-input

输出控制台

[NbConvertApp] Converting notebook SimpleNotebook.ipynb to notebook
[NbConvertApp] Executing notebook with kernel: python3
[NbConvertApp] Writing 18547 bytes to SimpleNotebook.nbconvert.ipynb
[NbConvertApp] Converting notebook SimpleNotebook.ipynb to html
[NbConvertApp] Executing notebook with kernel: python3
[NbConvertApp] Writing 280188 bytes to SimpleNotebook.html

它创造了

jupyter nbconvert SimpleNotebook.ipynb --to notebook --execute --no-input jupyter nbconvert SimpleNotebook.ipynb --to html --execute --no-input

问题:运行 两次。正如我在控制台输出中看到的:

[NbConvertApp] Executing notebook with kernel: python3

发生两次,因为它为每个命令行再次执行笔记本。

我想同时输出文件 SimpleNotebook.nbconvert.ipynb 和SimpleNotebook.html,但只执行笔记本一次。我应该如何编写命令行?

您不想在第二个命令中使用 --execute。并确保使用第一个命令的输出作为第二个命令的输入。

以下将使用您的示例替换您的两个命令:

jupyter nbconvert SimpleNotebook.ipynb --to notebook --execute 
jupyter nbconvert SimpleNotebook.nbconvert.ipynb --to html --no-input