Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export to html fails with jinja template problem #9468

Closed
rchiodo opened this issue Mar 24, 2022 · 11 comments · Fixed by #9484
Closed

Export to html fails with jinja template problem #9468

rchiodo opened this issue Mar 24, 2022 · 11 comments · Fixed by #9484
Labels
debt Code quality issues
Milestone

Comments

@rchiodo
Copy link
Contributor

rchiodo commented Mar 24, 2022

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.

@rchiodo rchiodo added the bug Issue identified by VS Code Team member as probable bug label Mar 24, 2022
@DonJayamanne DonJayamanne added debt Code quality issues engineering and removed bug Issue identified by VS Code Team member as probable bug needs-triage labels Mar 24, 2022
@HankSheehan
Copy link

I'm seeing the same issue. It seems to be that Jinja2 updated and changed where you should import the Markup object from.

https://jinja.palletsprojects.com/en/3.1.x/changes/#version-3-1-0

Markup and escape should be imported from MarkupSafe

@rchiodo
Copy link
Contributor Author

rchiodo commented Mar 24, 2022

We probably need another condition here:

@rchiodo
Copy link
Contributor Author

rchiodo commented Mar 24, 2022

No it looks like this is a bug in nbconvert. Here:
jupyter/nbconvert#1736

@rchiodo
Copy link
Contributor Author

rchiodo commented Mar 24, 2022

We might forcefully pin jinja2 to something older for the meantime.

@rchiodo
Copy link
Contributor Author

rchiodo commented Mar 24, 2022

Workaround, downgrade jinja2 to 3.0.3

python -m pip install -I jinja2==3.0.3

@rchiodo
Copy link
Contributor Author

rchiodo commented Mar 25, 2022

This isn't fixed, we just worked around it in our tests? @DonJayamanne maybe you didn't mean to close it.

@rchiodo rchiodo added this to the May 2022 milestone Apr 27, 2022
gar1t added a commit to guildai/guildai that referenced this issue Apr 28, 2022
Driver is that nbconvert to html breaks. [This
issue](microsoft/vscode-jupyter#9468)
describes it.
@rchiodo
Copy link
Contributor Author

rchiodo commented May 25, 2022

This should be fixed now.

@rchiodo rchiodo closed this as completed May 25, 2022
@fayddelight
Copy link

Workaround, downgrade jinja2 to 3.0.3

python -m pip install -I jinja2==3.0.3

thanks that worked for me!

@LizMcQuillan
Copy link

LizMcQuillan commented Jul 16, 2022

Downgrading jinja2 doesn't resolve this issue for me. Any other workarounds?

@thehappycheese
Copy link

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

@MrNickArcher
Copy link

Ran into this problem today. again - Python 3.9. The work-around suggested by rchiodo above worked again.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
debt Code quality issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants