-
Notifications
You must be signed in to change notification settings - Fork 567
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
TemplateNotFound error when extending built-in template #1394
Comments
I am having the exact same issue with the following API code in my tool. report_config = Config({'ExecutePreprocessor': {'enabled': True,
'timeout': 3600},
'HTMLExporter': {'template_paths': [template_path],
'template_file': 'report.tpl'}})
exportHtml = HTMLExporter(config=report_config)
output, _ = exportHtml.from_filename(notebook_file)
It used to work just perfectly with the previous versions of nbconvert but since 6.0.2 came out, I am seeing the following error: Executing notebook with kernel: python3
Traceback (most recent call last):
File "/Users/nmadnani/anaconda/envs/rsmdev/bin/rsmtool", line 33, in <module>
sys.exit(load_entry_point('rsmtool', 'console_scripts', 'rsmtool')())
File "/Users/nmadnani/work/rsmtool/rsmtool/rsmtool.py", line 374, in main
overwrite_output=args.force_write)
File "/Users/nmadnani/work/rsmtool/rsmtool/rsmtool.py", line 321, in run_experiment
figdir)
File "/Users/nmadnani/work/rsmtool/rsmtool/reporter.py", line 688, in create_report
join(reportdir, '{}.html'.format(report_name)))
File "/Users/nmadnani/work/rsmtool/rsmtool/reporter.py", line 327, in convert_ipynb_to_html
output, _ = exportHtml.from_filename(notebook_file)
File "/Users/nmadnani/anaconda/envs/rsmdev/lib/python3.6/site-packages/nbconvert/exporters/exporter.py", line 182, in from_filename
return self.from_file(f, resources=resources, **kw)
File "/Users/nmadnani/anaconda/envs/rsmdev/lib/python3.6/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 "/Users/nmadnani/anaconda/envs/rsmdev/lib/python3.6/site-packages/nbconvert/exporters/html.py", line 122, in from_notebook_node
return super().from_notebook_node(nb, resources, **kw)
File "/Users/nmadnani/anaconda/envs/rsmdev/lib/python3.6/site-packages/nbconvert/exporters/templateexporter.py", line 382, in from_notebook_node
output = self.template.render(nb=nb_copy, resources=resources)
File "/Users/nmadnani/anaconda/envs/rsmdev/lib/python3.6/site-packages/jinja2/environment.py", line 1090, in render
self.environment.handle_exception()
File "/Users/nmadnani/anaconda/envs/rsmdev/lib/python3.6/site-packages/jinja2/environment.py", line 832, in handle_exception
reraise(*rewrite_traceback_stack(source=source))
File "/Users/nmadnani/anaconda/envs/rsmdev/lib/python3.6/site-packages/jinja2/_compat.py", line 28, in reraise
raise value.with_traceback(tb)
File "/Users/nmadnani/work/rsmtool/rsmtool/notebooks/templates/report.tpl", line 1, in top-level template code
{%- extends "full.tpl" -%}
jinja2.exceptions.TemplateNotFound: full.tpl I also tried using |
I see the issue. It's a bug in how the templates are referring to local files when being imported from a different template directory. @maartenbreddels @SylvainCorlay could use your eyes on this to brainstorm how we might remedy the transitive pathing issue here. For compatibility templates in #1387 I added the extra template paths explicitly to handle this but seeing these reports of issues I think that might be the wrong approach to that aspect of the problem. |
In the meantime, until this is resolved, is there a possible workaround? I have the same issue, using a custom template that extends
I tried to copy all files from
Found the css files: If these are also present locally (from where nbconvert is run), then everything works. However, all code-cells have no syntax highlighted in the output HTML. I finally used the workaround |
Until I get the PR in to fix transitive dependency pathing, you can add |
This overall issue should now be resolved for backwards compatibility in 6.0.7 if you additionally set the |
I was able to help myself by reading this thread. Basically, I copied static folder content to where nbconvert was missing it. |
Many thanks, I can confirm this works now in Here are two tested sample files.
|
Hasn't fixed the issue yet? I tried to downgrade to
and while trying to run nbconvert:
I think I should downgrade jinja2 as well, but I'm not sure what other packages may break. |
Same issue with 7.6.0 |
@MSeal Could I ask for your attention here since you closde this? |
If we have to downgrade to v5.6.x, what's the point for nbconvert development? |
My workaround still works with the latest nbconvert and Jupyter versions. Does it work for you? |
Dann. My mistake. config file was misnamed🙈
Alexander Dunkel ***@***.***> schrieb am Di., 4. Juli 2023,
18:50:
… My workaround
<#1394 (comment)>
still works with the latest nbconvert and Jupyter versions. Does it work
for you?
—
Reply to this email directly, view it on GitHub
<#1394 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AHAWKXOXIUWV6DXYB6VCP6TXORCWRANCNFSM4RMZ73KA>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
I have the following code:
and a template (which does nothing but still fails if it does do something) in the cwd,
foo.tpl
:I get the error (with the venv path replaced with
<venv>
for brevity):It seems to be finding my
foo.tpl
file correctly, seeing theextends 'lab/index.html.j2'
line and then correctly finding<venv>/share/jupyter/nbconvert/templates/lab/index.html.j2
. This file, inside the install directory says itextends 'base.html.j2'
but nbconvert fails to find that file.If I do
ls <venv>/share/jupyter/nbconvert/templates/lab/
then I see:so
base.html.j2
is sitting there right next toindex.html.j2
.This process works fine with nbconvert 5. I realise that templates have changed and I read https://nbconvert.readthedocs.io/en/latest/customizing.html but it doesn't seem to tell me how to create a custom template, only how the built-in templates are organised.
The text was updated successfully, but these errors were encountered: