问题描述
我已经制作了一个自定义的nbconvert模板,并希望可以从启动nbconvert
实用程序的任何文件夹中对其进行访问.我应该在哪里放置模板?
I've made a custom nbconvert template and want it to be accessible from any folder where I launch nbconvert
utility. Where should I put my template?
我在官方文档中找不到任何内容.我已经尝试了通常的Jupyter配置设置,例如/usr/share/jupyter
,~/.local/share/jupyter
,~/.jupyter
,但无济于事.
I couldn't find anything in official docs. I have already tried usual places for jupyter configs, like /usr/share/jupyter
, ~/.local/share/jupyter
, ~/.jupyter
, to no avail.
到目前为止,我唯一找到的地方是python包所在的文件夹:
The only place I've found so far is the folder where python package lives:
$ 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时都需要重新做一次.
If I create nbconvert/templates/html
directory there and put my template in it, nbconvert --to html --template <my_template_name> ...
works fine. But this is an ugly hack which I'll need to re-do every time I update nbconvert.
似乎我可以为nbconvert提供环境变量,但我希望避免使用此选项.
Seems that I can provide nbconvert with environment variable, but I would prefer to avoid this option.
推荐答案
您需要通过创建 jupyter_nbconvert_config.py
文件并将其存储在~/.jupyter
中.
我将其用于LaTeX,这是我的文件的样子:
I use this for LaTeX--here's what my file looks like:
import os
c = get_config()
c.LatexExporter.template_path = ['.', os.path.expanduser('~/.jupyter/templates')]
c.LatexExporter.template_file = 'custom_latex.tplx'
假设模板扩展了现有模板,则在设置template_path
时需要包括'.'
,这样它才能知道在哪里查找标准模板.
Assuming you template extends an existing one, you need to include '.'
when setting template_path
so it knows where to look for the standard templates.
这篇关于放置自定义nbconvert模板的正确位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!