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

9

17

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:
    /home/.local/share/jupyter
    /usr/local/share/jupyter
    /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!

Heathcote answered 18/9, 2020 at 15:25 Comment(0)
P
16

I had the same issue after upgrading nbconvert to 6.0.8.

Rolling back to nbconvert 5.6.1 solved the problem for me.

pip uninstall nbconvert
pip install nbconvert==5.6.1

Progress answered 10/3, 2021 at 20:56 Comment(0)
D
14

For me, uninstalling and installing nbconvert using:

pip uninstall nbconvert
pip install nbconvert

fixed this error.

Dhaulagiri answered 5/10, 2020 at 15:26 Comment(0)
B
8

On Mac, if you installed jupyter using pip3 on user mode

ln -s ~/Library/Python/3.8/share/jupyter/nbconvert ~/Library/Jupyter/nbconvert

Just replace the 3.8 with the approriate version

Barcellona answered 7/7, 2021 at 23:51 Comment(0)
A
7

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/
Astrid answered 22/9, 2020 at 10:52 Comment(3)
On Windows 10 the template files were installed at: C:\Users\{username}\AppData\Roaming\Python\share\jupyter\nbconvert I copied them to: C:\Users\{username}\AppData\Roaming\jupyter\nbconvert\templatesRocher
@JeremyWhitcher Your comment solved my problem. I genuinely thank you.Tiertza
@JeremyWhitcher Many thanks. Your advice helped me to download a notebook as an HTML-file.Melonymelos
I
7

On Mac, very similar to @denis solution, just the locations are diffferent:

cd /opt/homebrew/opt/[email protected]/Frameworks/Python.framework/Versions/3.9/share/jupyter/nbconvert/
mv templates templates-tmp
ln -s /opt/homebrew/share/jupyter/nbconvert/templates
Icing answered 30/6, 2021 at 5:31 Comment(1)
This worked in my case, except just had to create the jupyter/nbconvert/ directory in share since it didn't already exist.Zeldazelde
C
2

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.

Centrum answered 19/9, 2020 at 11:55 Comment(0)
C
2

Depending on your installation locations you might want to adjust "path" and "target" variables below. In my case (Windows 10 with python installed from the Microsoft store and jupyter via pip) the following resolved the issue with jupyter not finding nbconvert. You will need to use elevated power shell (PS) to create link in APPDATA

PS > $path=$env:APPDATA+"\jupyter\nbconvert"
PS > $target=$env:LOCALAPPDATA+"\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\share\jupyter\nbconvert"
PS > New-Item -ItemType SymbolicLink -path "$path" -target "$target"

This should create link in appropriate location

Canna answered 11/7, 2021 at 13:51 Comment(0)
O
2

Had the same Issue (Mac Monterey 12.01)

Download nbconvert from GitHub and install solved it for me : Based on : https://github.com/jupyter/nbconvert

Orleanist answered 27/11, 2021 at 13:48 Comment(0)
D
0

To find out where your templates are, you can try to pip uninstall nbconvert

The templates will be included with a list of things you're trying to uninstall when asked if you want to proceed. You can then symlink that directory using the same advice as given in other answers here.

Drift answered 16/8 at 4:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.