question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Export to html fails with jinja template problem

See original GitHub issue

Nightly build is failing with this error:

CSSHTMLHeaderPreprocessor [NbConvertApp] Attempting to load template index.html.j2 [NbConvertApp]     template_paths: /opt/hostedtoolcache/Python/3.9.10/x64/share/jupyter/nbconvert/templates/lab:/opt/hostedtoolcache/Python/3.9.10/x64/share/jupyter/nbconvert/templates/base:/home/runner/.local/share/jupyter:/home/runner/.local/share/jupyter/nbconvert/templates:/home/runner/.local/share/jupyter/nbconvert/templates/compatibility:/opt/hostedtoolcache/Python/3.9.10/x64/share/jupyter:/opt/hostedtoolcache/Python/3.9.10/x64/share/jupyter/nbconvert/templates:/opt/hostedtoolcache/Python/3.9.10/x64/share/jupyter/nbconvert/templates/compatibility:/usr/local/share/jupyter:/usr/local/share/jupyter/nbconvert/templates:/usr/local/share/jupyter/nbconvert/templates/compatibility:/usr/share/jupyter:/usr/share/jupyter/nbconvert/templates:/usr/share/jupyter/nbconvert/templates/compatibility:/opt/hostedtoolcache/Python/3.9.10/x64/share/jupyter/nbconvert/templates Traceback (most recent call last):   File "/opt/hostedtoolcache/Python/3.9.10/x64/bin/jupyter-nbconvert", line 8, in <module>     sys.exit(main())   File "/opt/hostedtoolcache/Python/3.9.10/x64/lib/python3.9/site-packages/jupyter_core/application.py", line 264, in launch_instance     return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)   File "/opt/hostedtoolcache/Python/3.9.10/x64/lib/python3.9/site-packages/traitlets/config/application.py", line 846, in launch_instance     app.start()   File "/opt/hostedtoolcache/Python/3.9.10/x64/lib/python3.9/site-packages/nbconvert/nbconvertapp.py", line 369, in start     self.convert_notebooks()   File "/opt/hostedtoolcache/Python/3.9.10/x64/lib/python3.9/site-packages/nbconvert/nbconvertapp.py", line 541, in convert_notebooks     self.convert_single_notebook(notebook_filename)   File "/opt/hostedtoolcache/Python/3.9.10/x64/lib/python3.9/site-packages/nbconvert/nbconvertapp.py", line 506, in convert_single_notebook     output, resources = self.export_single_notebook(notebook_filename, resources, input_buffer=input_buffer)   File "/opt/hostedtoolcache/Python/3.9.10/x64/lib/python3.9/site-packages/nbconvert/nbconvertapp.py", line 435, in export_single_notebook     output, resources = self.exporter.from_filename(notebook_filename, resources=resources)   File "/opt/hostedtoolcache/Python/3.9.10/x64/lib/python3.9/site-packages/nbconvert/exporters/exporter.py", line 190, in from_filename     return self.from_file(f, resources=resources, **kw)   File "/opt/hostedtoolcache/Python/3.9.10/x64/lib/python3.9/site-packages/nbconvert/exporters/exporter.py", line 208, in from_file     return self.from_notebook_node(nbformat.read(file_stream, as_version=4), resources=resources, **kw)   File "/opt/hostedtoolcache/Python/3.9.10/x64/lib/python3.9/site-packages/nbconvert/exporters/html.py", line 210, in from_notebook_node     return super().from_notebook_node(nb, resources, **kw)   File "/opt/hostedtoolcache/Python/3.9.10/x64/lib/python3.9/site-packages/nbconvert/exporters/templateexporter.py", line 392, in from_notebook_node     output = self.template.render(nb=nb_copy, resources=resources)   File "/opt/hostedtoolcache/Python/3.9.10/x64/lib/python3.9/site-packages/jinja2/environment.py", line 1291, in render     self.environment.handle_exception()   File "/opt/hostedtoolcache/Python/3.9.10/x64/lib/python3.9/site-packages/jinja2/environment.py", line 926, in handle_exception     raise rewrite_traceback_stack(source=source)   File "/opt/hostedtoolcache/Python/3.9.10/x64/share/jupyter/nbconvert/templates/lab/index.html.j2", line 3, in top-level template code     {% from 'jupyter_widgets.html.j2' import jupyter_widgets %}   File "/opt/hostedtoolcache/Python/3.9.10/x64/share/jupyter/nbconvert/templates/lab/base.html.j2", line 260, in top-level template code     {% set div_id = uuid4() %}   File "/opt/hostedtoolcache/Python/3.9.10/x64/share/jupyter/nbconvert/templates/base/display_priority.j2", line 1, in top-level template code     {%- extends 'base/null.j2' -%}   File "/opt/hostedtoolcache/Python/3.9.10/x64/share/jupyter/nbconvert/templates/base/null.j2", line 24, in top-level template code     {%- block header -%}   File "/opt/hostedtoolcache/Python/3.9.10/x64/share/jupyter/nbconvert/templates/lab/index.html.j2", line 9, in block 'header'     {%- block html_head -%}   File "/opt/hostedtoolcache/Python/3.9.10/x64/share/jupyter/nbconvert/templates/lab/index.html.j2", line 36, in block 'html_head'     {% block notebook_css %}   File "/opt/hostedtoolcache/Python/3.9.10/x64/share/jupyter/nbconvert/templates/lab/index.html.j2", line 37, in block 'notebook_css'     {{ resources.include_css("static/index.css") }}   File "/opt/hostedtoolcache/Python/3.9.10/x64/lib/python3.9/site-packages/nbconvert/exporters/html.py", line 216, in resources_include_css     return jinja2.Markup(code) AttributeError: module 'jinja2' has no attribute 'Markup'

I can’t seem to repro locally. Maybe only on linux does it fail.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:3
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

8reactions
rchiodocommented, Mar 24, 2022

Workaround, downgrade jinja2 to 3.0.3

python -m pip install -I jinja2==3.0.3
0reactions
thehappycheesecommented, Oct 21, 2022

Ran into this problem today in vs code - Python 3.9. The work-around suggested by rchiodo above worked perfectly for me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jinja2 not loading template - Stack Overflow
I was following this tutorial and although I seem to doing everything correctly it is not able to find the template. jinja ├──...
Read more >
API — Jinja Documentation (3.1.x)
To load a template from this environment, call the get_template() method, which returns the loaded Template . template = env.get_template("mytemplate.html").
Read more >
BashOperator — Airflow Documentation
t2 = BashOperator( task_id="bash_example", # This fails with 'Jinja template not found' error # bash_command="/home/batcher/test.sh", # This works (has a ...
Read more >
Primer on Jinja Templating - Real Python
If you don't provide context for the variables in a template, they don't throw an error. But they render an empty string, which...
Read more >
Jinja Errors - Bloomreach Documentation
The error occurs when jinja is too complex. For example, when there are too many calls in catalogs or recommendations, too long computing...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found