我制作了一个自定义 nbconvert 模板,并希望可以从我启动的任何文件夹访问它 nbconvert
公用事业。我应该把模板放在哪里?
我在官方文档中找不到任何内容。我已经尝试过 jupyter 配置的常用位置,比如 /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 提供环境变量,但我宁愿避免使用此选项。
最佳答案
您需要通过创建 jupyter_nbconvert_config.py
来告诉 nbconvert
查找您的模板文件并将其存储在 ~/.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
时包含 '.'
,以便它知道在哪里寻找标准模板。
关于python - 放置自定义 nbconvert 模板的正确位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51137110/