Nbconvert: Error when exporting to HTML: `TemplateNotFound: static/index.css` (introduced in 6.0.0a2)

Created on 4 Sep 2020  路  20Comments  路  Source: jupyter/nbconvert

I am trying to export an empty notebook to HTML (jupyter nbconvert --to html empty.ipynb), but it fails with TemplateNotFound: static/index.css (full error message below). I tried b7 and master, and the error is still there; a1 and earlier works fine.

(A caveat is that depending on which version I was on before upgrading, I seemed to get inconsistent results, e.g. being on a1 and then updating to b7 sometimes worked, but being on a6 and upgrading to b7 caused the error. So to reproduce, run pip install https://github.com/jupyter/nbconvert/archive/6.0.0a6.zip and then pip install https://github.com/jupyter/nbconvert/archive/6.0.0b7.zip. Sometimes it works when upgrading to master, sometimes not. Is there a template file generated that is cleared by some versions maybe?)

Error message

[NbConvertApp] Converting notebook empty.ipynb to html
Traceback (most recent call last):
  File "/home/joel/miniconda3/envs/mds/bin/jupyter-nbconvert", line 8, in 
    sys.exit(main())
  File "/home/joel/miniconda3/envs/mds/lib/python3.8/site-packages/jupyter_core/application.py", line 270, in launch_instance
    return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
  File "/home/joel/miniconda3/envs/mds/lib/python3.8/site-packages/traitlets/config/application.py", line 838, in launch_instance
    app.start()
  File "/home/joel/miniconda3/envs/mds/lib/python3.8/site-packages/nbconvert/nbconvertapp.py", line 345, in start
    self.convert_notebooks()
  File "/home/joel/miniconda3/envs/mds/lib/python3.8/site-packages/nbconvert/nbconvertapp.py", line 519, in convert_notebooks
    self.convert_single_notebook(notebook_filename)
  File "/home/joel/miniconda3/envs/mds/lib/python3.8/site-packages/nbconvert/nbconvertapp.py", line 484, in convert_single_notebook
    output, resources = self.export_single_notebook(notebook_filename, resources, input_buffer=input_buffer)
  File "/home/joel/miniconda3/envs/mds/lib/python3.8/site-packages/nbconvert/nbconvertapp.py", line 413, in export_single_notebook
    output, resources = self.exporter.from_filename(notebook_filename, resources=resources)
  File "/home/joel/miniconda3/envs/mds/lib/python3.8/site-packages/nbconvert/exporters/exporter.py", line 182, in from_filename
    return self.from_file(f, resources=resources, **kw)
  File "/home/joel/miniconda3/envs/mds/lib/python3.8/site-packages/nbconvert/exporters/exporter.py", line 200, in from_file
    return self.from_notebook_node(nbformat.read(file_stream, as_version=4), resources=resources, **kw)
  File "/home/joel/miniconda3/envs/mds/lib/python3.8/site-packages/nbconvert/exporters/html.py", line 122, in from_notebook_node
    return super().from_notebook_node(nb, resources, **kw)
  File "/home/joel/miniconda3/envs/mds/lib/python3.8/site-packages/nbconvert/exporters/templateexporter.py", line 377, in from_notebook_node
    output = self.template.render(nb=nb_copy, resources=resources)
  File "/home/joel/.local/lib/python3.8/site-packages/jinja2/environment.py", line 1090, in render
    self.environment.handle_exception()
  File "/home/joel/.local/lib/python3.8/site-packages/jinja2/environment.py", line 832, in handle_exception
    reraise(*rewrite_traceback_stack(source=source))
  File "/home/joel/.local/lib/python3.8/site-packages/jinja2/_compat.py", line 28, in reraise
    raise value.with_traceback(tb)
  File "/home/joel/miniconda3/envs/mds/share/jupyter/nbconvert/templates/lab/index.html.j2", line 3, in top-level template code
    {% from 'jupyter_widgets.html.j2' import jupyter_widgets %}
  File "/home/joel/miniconda3/envs/mds/share/jupyter/nbconvert/templates/lab/base.html.j2", line 169, in top-level template code

  File "/home/joel/miniconda3/envs/mds/share/jupyter/nbconvert/templates/base/display_priority.j2", line 1, in top-level template code
    {%- extends 'base/null.j2' -%}
  File "/home/joel/miniconda3/envs/mds/share/jupyter/nbconvert/templates/base/null.j2", line 23, in top-level template code
    #}
  File "/home/joel/miniconda3/envs/mds/share/jupyter/nbconvert/templates/lab/index.html.j2", line 6, in block "header"
    
  File "/home/joel/miniconda3/envs/mds/share/jupyter/nbconvert/templates/lab/index.html.j2", line 28, in block "html_head"
    {% endblock extra_css %}
  File "/home/joel/miniconda3/envs/mds/share/jupyter/nbconvert/templates/lab/index.html.j2", line 29, in block "notebook_css"

  File "/home/joel/miniconda3/envs/mds/lib/python3.8/site-packages/nbconvert/exporters/html.py", line 127, in resources_include_css
    code = """""" % (env.loader.get_source(env, name)[0])
  File "/home/joel/.local/lib/python3.8/site-packages/jinja2/loaders.py", line 488, in get_source
    raise TemplateNotFound(template)
jinja2.exceptions.TemplateNotFound: static/index.css

Tested on Linux and Windows

# Linux jupyter --version
jupyter core     : 4.6.3
jupyter-notebook : 6.1.3
qtconsole        : not installed
ipython          : 7.18.1
ipykernel        : 5.3.4
jupyter client   : 6.1.2
jupyter lab      : 2.2.6
nbconvert        : 6.0.0b7
ipywidgets       : not installed
nbformat         : 5.0.5
traitlets        : 5.0.0

# Windows jupyter --version
$ jupyter --version
jupyter core     : 4.6.3
jupyter-notebook : 6.1.3
qtconsole        : not installed
ipython          : 7.17.0
ipykernel        : 5.3.4
jupyter client   : 6.1.6
jupyter lab      : 2.2.5
nbconvert        : 6.0.0b7
ipywidgets       : not installed
nbformat         : 5.0.7
traitlets        : 4.3.3

Most helpful comment

@Ghabry I opened an issue there a few days ago and just pasted the lasted comment from above also https://bugs.archlinux.org/task/69537

All 20 comments

Sorry for missing this post originally -- let me dig into this now.

@MSeal Thank you! I just discovered that this only seems to be a problem when installing from .zip or .tar.gz release on Github. installing from a commit works reproducibly now.

So this works (in a clean env with just jupyterlab installed) :

pip install git+https://github.com/jupyter/nbconvert.git@db0e589

but this does not

pip install https://github.com/jupyter/nbconvert/archive/6.0.0rc0.zip

I don't understand why this is, but it likely means that this does not need attention before the 6.0 release, and I edited my comment at the release issue to reflect that.

Huh that is interesting. There are some lab template styling that get's fetched if it's missing. That might explain the discrepancy but I'll have to think on it more (having difficulty reproducing atm).

Just to be clear with exactly what I run since you're having issues reproducing:

conda create -n nbc-test jupyterlab
conda activate nbc-test
pip install https://github.com/jupyter/nbconvert/archive/6.0.0rc0.tar.gz
jupyter nbconvert --to html empty.ipynb

I also tried installing jupyterlab via pip, just to see if it was conda related for some reason, but it seems not to be, I get the same error when running this:

conda create -n nbc-test pip
conda activate nbc-test
pip install jupyterlab
pip install https://github.com/jupyter/nbconvert/archive/6.0.0rc0.tar.gz
jupyter nbconvert --to html empty.ipynb

Ok yeah that reproduces on my machine -- I typically don't develop in conda and it doesn't reproduce in a pure venv setting.

I guess this is a pretty minor issue then, as it only affects people using conda together with installing a GitHub archive instead of a commit ref with pip.

I don't know what pip assumes of a package when it comes across a zip file. If it treats it as a wheel, then it is clearly not correct.

FYI, I got same error with my regacy utitiliy like this.

import nbformat
from nbconvert.exporters import HTMLExporter
from traitlets.config import Config

json = nbformat.read(open("Untitled.ipynb"), nbformat.current_nbformat)

c = Config( { "TemplateExporter": {"template_file": "basic.tpl"}})
html, _ = HTMLExporter(c).from_notebook_node(json)
print(html)

This code works with nbconvert 5.6.1, but raises same error with 6.0.6.

Changing Config to

c = Config({"TemplateExporter": {"template_name": "classic", "template_file": "base.html.j2"}})

fixes problem in my case.

I guess this is a pretty minor issue then, as it only affects people using conda together with installing a GitHub archive instead of a commit ref with pip.

When trying to convert a notebook i'll have this error too.

I've installed jupyter-notebook as well as jupyter-nbconvert via pacman on Arch Linux.

Current python version: 3.9.1
Jupyter-Notebook Version: 6.2.0
Jupyter-NBConvert Version: 6.0.7

The installation directory for the nbconvert-templates (/usr/share/jupyter/nbconvert/templates/..) doesn't contain any index.css. These two are the only *.css-files found:

*/reveal/static/custom_reveal.css
*/classic/static/style.css

The only template files (*.tpl) found are:

*/compatibility/full.tpl
*/compatibility/display_priority.tpl

Are there some files missing?

@JanFeld @atsuoishimoto it would be useful to know how you installed nbconvert.

@JanFeld @atsuoishimoto it would be useful to know how you installed nbconvert.

I've installed everything via pacman an Arch Linux 5.10.11

pacman -S jupyter jupyter-notebook jupyter-nbconvert

Can confirm, have the same problem with Arch Linux.

Mildly annoying, because until two weeks ago I uploaded next to the ipynb a HTML for my students as the HTML version is easier to view.

Possibly of interest, I am also on Arch, but I installed it via conda and pip (as detailed above). I believe I tried Windows as well with the same result.

I'm also having the same problem with Arch Linux. Creating a script as suggested by @atsuoishimoto it works out but the command line command for converting does not work.

I think the pacman package is broken, which would explain the reports on Arch Linux.

I think the pacman package is broken, which would explain the reports on Arch Linux.

Pacman package builder simply runs python3 setup.py install. From what I see in setup.py, it hooks 'build' target (or phase?) but doesn't add anything for 'install' target (well, if it's phase, then should have inherited 'css' execution from 'build', but it seems it hasn't).

Fedora seem to run 'build' before 'install', maybe that's the way to go?

The way to go for the pacman package maintainer is

python -m pip install . --no-deps --ignore-installed --no-cache-dir -vvv

Generally, for packaging the Jupyter stack, I recommend looking at the recipes of the conda packages, which are maintainers by the package authors: https://github.com/conda-forge/nbconvert-feedstock/blob/master/recipe/meta.yaml#L13

So this must be a packaging bug that should be reported on https://bugs.archlinux.org/ (and then linked to this issue)

@joelostblom @juanscr anyone of you having an account already for the arch bugtracker? I'm not a fan of registering accounts that I will only use once, so would be great if someone with an account could file it there :/.

@Ghabry I opened an issue there a few days ago and just pasted the lasted comment from above also https://bugs.archlinux.org/task/69537

Was this page helpful?
0 / 5 - 0 ratings

Related issues

matthias-k picture matthias-k  路  4Comments

karimbk picture karimbk  路  3Comments

Carreau picture Carreau  路  4Comments

mwsmws22 picture mwsmws22  路  3Comments

guerreroda picture guerreroda  路  3Comments