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

发布于 2021-01-29 14:10:12

我已经制作了一个自定义的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提供环境变量,但我希望避免使用此选项。

关注者
0
被浏览
195
1 个回答
  • 面试哥
    面试哥 2021-01-29
    为面试而生,有面试问题,就找面试哥。

    您需要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以便知道在哪里寻找标准模板。



知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看