No template sub-directory with name 'lab' found in the following paths

情到浓时终转凉″ 提交于 2021-02-08 15:38:10

问题


I am running a python azure function which is running a jupyter notebook via the nbconvert API. This was working for a time, although without deploying new code I have started to get the following error:

No template sub-directory with name 'lab' found in the following paths:\n\t/home/.local/share/jupyter\n\t/usr/local/share/jupyter\n\t/usr/share/jupyter

The code I am using to achieve this is:

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)

The functionapp is running the following:

python3.6
nbconvert6.0.3
jupyter-lab0.1.1

I have tried googling the error, the closest thing I have found so far is this which is similar but unanswered and not completely the same. Thought I'd post here to see if anyone knows how to resolve or for me to update if I manage to resolve the issue.

I am quite confused as lab is not a keyword I am familiar with (outside of maybe jupyterlab) and isn't being used within the code.

As for the paths mentioned:

  • home/.local/share/jupyter/ exists and contains nbconvert/templates/html
  • usr/local/share/jupyter & usr/share/jupyter don't exist

Thanks in advance for any help!


回答1:


For me, uninstalling and installing nbconvert using:

pip uninstall nbconvert
pip install nbconvert

fixed this error.




回答2:


pip install -U nbconvert installs .../site-packages/share/jupyter/nbconvert/templates/
but jupyter nbconvert my.ipynb --to python doesn't look there --

# 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

Make a symbolic link in one of these to .../site-packages/.../templates, e.g.

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/



回答3:


I'm getting the same exact error. I am assuming the default/built in templates were just installed during anaconda installation. I think we have to look at older versions of jupyter notebook / nbconvert / anaconda and just copy and paste the template files.



来源:https://stackoverflow.com/questions/63958574/no-template-sub-directory-with-name-lab-found-in-the-following-paths

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!