【问题标题】:How to resolve TemplateNotFound error when upgrading nbconvert to 6.x+?将 nbconvert 升级到 6.x+ 时如何解决 TemplateNotFound 错误?
【发布时间】:2020-10-25 20:38:57
【问题描述】:

在尝试使用我过去使用的模板制作基于 Jupyter 的新演示文稿时,我发现当 nbconvert 升级到 6.0 以上时,我收到与缺少内置模板 @987654324 相关的错误@。一个最小的复制器,创建一个名为custom.tpl的模板文件:

{% extends 'basic.tpl' %}

然后使用任何 Jupyter 笔记本和 pip install jupyter nbconvert 并运行 nbconvert notebook.ipynb --to=slides --template=custom.tpl。你会得到这样的异常:

[NbConvertApp] Converting notebook example.ipynb to slides
Traceback (most recent call last):
  File "/tmp/tmp.niaMlxSIbz/venv/bin/jupyter-nbconvert", line 8, in <module>
    sys.exit(main())
...
  File "/tmp/tmp.niaMlxSIbz/custom.tpl", line 1, in top-level template code
    {% extends 'basic.tpl' %}
jinja2.exceptions.TemplateNotFound: basic.tpl

如果你pip install 'nbconvert &lt; 6.0',你会发现同样的命令成功了。

我想这与changes to how templates work that came in 6.0 相关,但我相信.tpl 模板仍将被支持,甚至列出了PR that restores the basic template,但我在任何地方都找不到有关如何更新的说明我的模板,其中包含对新位置的引用。

有没有办法通过更改对'basic.tpl' 的引用来解决这个问题?

固定到 5.6.1“有效”,但 nbconvert 的 5.6.1 版不适用于 Python 3.9,我需要访问我笔记本中的一些较新的 Python 功能。

【问题讨论】:

    标签: jupyter-notebook jupyter nbconvert


    【解决方案1】:

    我不知道.tpl 文件是否直接向后兼容,但您可以将模板指令迁移到新的模板目录格式。

    使用jupyter --paths 查找您的用户(或系统)jupyter 配置路径。从那里,您可以将自定义模板添加到模板目录中。

    $ jupyter --paths                                                 (master) ✓
    config:
        /Users/txoof/.jupyter << user templates can be found here on my system
        /Users/txoof/.local/share/virtualenvs/folderAudit-FJk3azd9/etc/jupyter << jupyter default templates can be found here
        /usr/local/etc/jupyter  
        /etc/jupyter
    

    通过将默认系统模板之一复制到我的用户模板目录并将我的指令从我的 .tpl 文件粘贴到 index.py.j2 文件中,我取得了成功。

    您可以找到有关从 nbconvert 5 迁移到 6 here 的更多详细信息。

    截至 2020 年 11 月,从 5 迁移到 6 的文档非常糟糕,但 nbconvert issues at github 非常活跃且乐于助人。

    【讨论】:

      猜你喜欢
      • 2015-07-22
      • 1970-01-01
      • 2020-06-17
      • 1970-01-01
      • 1970-01-01
      • 2021-02-22
      • 1970-01-01
      • 1970-01-01
      • 2020-12-05
      相关资源
      最近更新 更多