小编典典

放置自定义nbconvert模板的正确位置

python

我已经制作了一个自定义的nbconvert模板,并希望可以从启动nbconvert实用程序的任何文件夹中对其进行访问。我应该在哪里放置模板?

我在官方文档中找不到任何内容。我已经尝试过平常的地方jupyter
CONFIGS一样/usr/share/jupyter~/.local/share/jupyter~/.jupyter,无济于事。

到目前为止,我唯一找到的地方是python包所在的文件夹:

$ pip show nbconvert | grep Location | cut -d" " -f2
/usr/lib/python3.6/site-packages

如果我nbconvert/templates/html在此处创建目录并将模板放在其中,则nbconvert --to html --template <my_template_name> ...效果很好。但这是一个丑陋的hack,每次我更新nbconvert时都需要重新做一次。

似乎我可以为nbconvert提供环境变量,但我希望避免使用此选项。


阅读 481

收藏
2021-01-20

共1个答案

小编典典

您需要nbconvert通过创建jupyter_nbconvert_config.py文件并将其存储在中来告诉您寻找模板~/.jupyter

我将其用于LaTeX-这是我的文件的样子:

import os
c = get_config()

c.LatexExporter.template_path = ['.', os.path.expanduser('~/.jupyter/templates')]
c.LatexExporter.template_file = 'custom_latex.tplx'

假设模板扩展了现有模板,则'.'在设置时需要包括在内,template_path以便知道在哪里寻找标准模板。

2021-01-20