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

2024-05-14 01:16:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在运行一个pythonazure函数,它通过nbconvertAPI运行一个jupyter笔记本。这已经运行了一段时间,但在没有部署新代码的情况下,我开始出现以下错误:

No template sub-directory with name 'lab' found in the following paths:
    /home/.local/share/jupyter
    /usr/local/share/jupyter
    /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)

functionapp正在运行以下操作:

python3.6
nbconvert6.0.3
jupyter-lab0.1.1

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

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

至于提到的路径:

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

提前感谢您的帮助


Tags: 代码namefromshareoutputusrlocalhtml
3条回答

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

回到nbconvert 5.6.1解决了我的问题

pip uninstall nbconvert
pip install nbconvert==5.6.1

对于我来说,使用以下方法卸载和安装nbconvert:

pip uninstall nbconvert
pip install nbconvert

修正了这个错误

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

在其中一个中创建一个到.../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/

相关问题 更多 >