在以下路径中找不到名为“lab”的模板子目录

Lia*_*ris 7 python jupyter jupyter-notebook azure-functions nbconvert

我正在运行一个 python azure 函数,它通过nbconvertAPI运行一个 jupyter 笔记本。这已经工作了一段时间,尽管没有部署新代码我开始收到以下错误:

在以下路径中找不到名为“lab”的模板子目录:\n\t/home/.local/share/jupyter\n\t/usr/local/share/jupyter\n\t/usr/share/ jupyter

我用来实现这一目标的代码是:

from nbconvert.preprocessors import ExecutePreprocessor
from nbconvert import HTMLExporter

...

dl = DictLoader({'footer':
"""
{%- extends 'full.tpl' -%}

{% block input_group %}
    {%- if cell.metadata.get('nbconvert', {}).get('show_code', False) -%}
        ((( super() )))
    {%- endif -%}
{% endblock input_group %}
{% block output_group %}
    <style> .output_prompt{visibility:hidden;}</style>
    {{ super() }}
{% endblock output_group %}
"""})

...

html_exporter = HTMLExporter(extra_loaders=[dl], template_file='footer')
html_exporter.template_name = 'classic'
with open(JUPYTER_DIR + NOTEBOOK_NAME) as f:
    nb = nbformat.read(f, as_version=4)

ep = ExecutePreprocessor(timeout=600, kernel_name='python')
ep.preprocess(nb, {'metadata': {'path': JUPYTER_DIR}})
(body, resources) = html_exporter.from_notebook_node(nb)
Run Code Online (Sandbox Code Playgroud)

functionapp 正在运行以下内容:

python3.6
nbconvert6.0.3
jupyter-lab0.1.1
Run Code Online (Sandbox Code Playgroud)

我试过在谷歌上搜索错误,到目前为止我发现的最接近的是这个,它是相似的但没有得到答复并且不完全相同。我想我会在这里发帖,看看是否有人知道如何解决,或者如果我设法解决了问题,我会更新。

我很困惑,因为lab它不是我熟悉的关键字(在可能之外jupyterlab)并且没有在代码中使用。

至于提到的路径:

  • home/.local/share/jupyter/ 存在并包含 nbconvert/templates/html
  • usr/local/share/jupyter&usr/share/jupyter不存在

在此先感谢您的帮助!

小智 10

对我来说,卸载和安装 nbconvert 使用:

pip uninstall nbconvert
pip install nbconvert
Run Code Online (Sandbox Code Playgroud)

修复了这个错误。


mla*_*tin 8

在 Mac 上,如果您在用户模式下使用 pip3 安装了 jupyter

ln -s ~/Library/Python/3.8/share/jupyter/nbconvert ~/Library/Jupyter/nbconvert
Run Code Online (Sandbox Code Playgroud)

只需将 3.8 替换为合适的版本即可


den*_*nis 7

pip install -U nbconvert安装了 .../site-packages/share/jupyter/nbconvert/templates/
jupyter nbconvert my.ipynb --to python看不到那里--

# ValueError: No template sub-directory with name 'base' found in the following paths:

/Users/myuserid/Library/Jupyter  # mac
/Library/Frameworks/Python.framework/Versions/3.7/share/jupyter
/usr/local/share/jupyter
/usr/share/jupyter
Run Code Online (Sandbox Code Playgroud)

在其中之一中创建一个符号链接.../site-packages/.../templates,例如

cd $HOME/Library/Jupyter/nbconvert  # mac, other platforms dunno
mv templates templates-tmp  # empty
ln -s .../site-packages/share/jupyter/nbconvert/templates .
ls templates/
# asciidoc/  classic/      html/  latex/     python/  rst/
# base/    compatibility/  lab/   markdown/  reveal/  script/
Run Code Online (Sandbox Code Playgroud)

  • 在 Windows 10 上,模板文件安装在:C:\Users\{username}\AppData\Roaming\Python\share\jupyter\nbconvert 我将它们复制到:C:\Users\{username}\AppData\Roaming\jupyter\ nbconvert\模板 (6认同)
  • @JeremyWhitcher你的评论解决了我的问题。我真诚地感谢你。 (2认同)

小智 7

将 nbconvert 升级到 6.0.8 后,我遇到了同样的问题。

回滚到 nbconvert 5.6.1 为我解决了这个问题。

pip uninstall nbconvert
pip install nbconvert==5.6.1


小智 6

在 Mac 上,与 @denis 解决方案非常相似,只是位置不同:

cd /opt/homebrew/opt/python@3.9/Frameworks/Python.framework/Versions/3.9/share/jupyter/nbconvert/
mv templates templates-tmp
ln -s /opt/homebrew/share/jupyter/nbconvert/templates
Run Code Online (Sandbox Code Playgroud)

  • 这在我的情况下有效,只是必须在“share”中创建“jupyter/nbconvert/”目录,因为它尚不存在。 (3认同)

小智 2

我遇到了同样的错误。我假设默认/内置模板刚刚在 anaconda 安装期间安装。我认为我们必须查看旧版本的 jupyter notebook / nbconvert / anaconda 并复制并粘贴模板文件。