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

Template Not Found: Unable to locate base.tplx or other built-in LaTeX templates #2154

Open
GitHubonline1396529 opened this issue Jun 6, 2024 · 1 comment

Comments

@GitHubonline1396529
Copy link

Description

I'm encountering an issue with nbconvert where it fails to locate built-in LaTeX templates such as base.tplx. Even though the templates are present in the expected directory (as following), nbconvert doesn't seem to recognize them.

latex $ pwd
/d/Python/Python39/share/jupyter/nbconvert/templates/latex
latex $ ls
base.tex.j2               index.tex.j2             style_bw_python.tex.j2
conf.json                 null.j2                  style_ipython.tex.j2
display_priority.j2       report.tex.j2            style_jupyter.tex.j2
document_contents.tex.j2  style_bw_ipython.tex.j2  style_python.tex.j2

I've followed the official documentation and tried several troubleshooting steps, including specifying the template path manually, but the problem persists.

Steps to Reproduce

  1. Install nbconvert and other Jupyter components using pip.

  2. Place a Jupyter notebook (notebook.ipynb) in a working directory. There's my working directory tree:

.
├── data
│   └── melon_data.csv
├── generator.py
├── image
│   └── center.png
├── latex
│   ├── notebook.tex
│   ├── notebook_files
│   │   ├── notebook_4_1.png
│   │   └── notebook_6_2.png
│   └── template
│       └── simple.tplx
└── notebook.ipynb

6 directories, 13 files
  1. Write a simple .tplx like the following one:
((*- extends 'base.tplx' -*))

((* block body *))
    ((( super() )))
((* endblock body *))
  1. Run the following command to convert the notebook to LaTeX:
   jupyter nbconvert --to latex --template-file ./latex/template/simple.tplx --output-dir ./latex/ ./notebook.ipynb --debug

Expected Behavior

nbconvert should successfully locate and use the base.tplx template (and other necessary templates) to convert the notebook to LaTeX format.

Actual Behavior

The conversion process fails with the following error:

jinja2.exceptions.TemplateNotFound: base.tplx

Debug Output

Here is the --debug output from the nbconvert command:

$ jupyter nbconvert --to latex --template-file ./latex/template/simple.tplx --output-dir ./latex/ ./notebook.ipynb --debug
[NbConvertApp] Searching ['C:\\Users\\asus\\.jupyter', 'D:\\Python\\Python39\\Scripts\\etc\\jupyter', 'D:\\Python\\Python39\\etc\\jupyter', 'C:\\ProgramData\\jupyter'] for config files
[NbConvertApp] Looking for jupyter_config in C:\ProgramData\jupyter
[NbConvertApp] Looking for jupyter_config in D:\Python\Python39\etc\jupyter
[NbConvertApp] Looking for jupyter_config in D:\Python\Python39\Scripts\etc\jupyter
[NbConvertApp] Looking for jupyter_config in C:\Users\asus\.jupyter
[NbConvertApp] Looking for jupyter_nbconvert_config in C:\ProgramData\jupyter
[NbConvertApp] Looking for jupyter_nbconvert_config in D:\Python\Python39\etc\jupyter
[NbConvertApp] Looking for jupyter_nbconvert_config in D:\Python\Python39\Scripts\etc\jupyter
[NbConvertApp] Looking for jupyter_nbconvert_config in C:\Users\asus\.jupyter
[NbConvertApp] Loaded config file: C:\Users\asus\.jupyter\jupyter_nbconvert_config.json
[NbConvertApp] Converting notebook ./notebook.ipynb to latex
[NbConvertApp] Notebook name is 'notebook'
Traceback (most recent call last):
  File "D:\Python\Python39\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "D:\Python\Python39\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "D:\Python\Python39\Scripts\jupyter-nbconvert.EXE\__main__.py", line 7, in <module>
  File "D:\Python\Python39\Lib\site-packages\jupyter_core\application.py", line 285, in launch_instance
    return super().launch_instance(argv=argv, **kwargs)
  File "D:\Python\Python39\Lib\site-packages\traitlets\config\application.py", line 1043, in launch_instance
    app.start()
  File "D:\Python\Python39\Lib\site-packages\nbconvert\nbconvertapp.py", line 420, in start
    self.convert_notebooks()
  File "D:\Python\Python39\Lib\site-packages\nbconvert\nbconvertapp.py", line 597, in convert_notebooks
    self.convert_single_notebook(notebook_filename)
  File "D:\Python\Python39\Lib\site-packages\nbconvert\nbconvertapp.py", line 563, in convert_single_notebook
    output, resources = self.export_single_notebook(
  File "D:\Python\Python39\Lib\site-packages\nbconvert\nbconvertapp.py", line 487, in export_single_notebook
    output, resources = self.exporter.from_filename(
  File "D:\Python\Python39\Lib\site-packages\nbconvert\exporters\templateexporter.py", line 386, in from_filename
    return super().from_filename(filename, resources, **kw)  # type:ignore[return-value]
  File "D:\Python\Python39\Lib\site-packages\nbconvert\exporters\exporter.py", line 201, in from_filename
    return self.from_file(f, resources=resources, **kw)
  File "D:\Python\Python39\Lib\site-packages\nbconvert\exporters\templateexporter.py", line 392, in from_file
    return super().from_file(file_stream, resources, **kw)  # type:ignore[return-value]
  File "D:\Python\Python39\Lib\site-packages\nbconvert\exporters\exporter.py", line 220, in from_file
    return self.from_notebook_node(
  File "D:\Python\Python39\Lib\site-packages\nbconvert\exporters\latex.py", line 92, in from_notebook_node
    return super().from_notebook_node(nb, resources, **kw)
  File "D:\Python\Python39\Lib\site-packages\nbconvert\exporters\templateexporter.py", line 424, in from_notebook_node
    output = self.template.render(nb=nb_copy, resources=resources)
  File "D:\Python\Python39\Lib\site-packages\jinja2\environment.py", line 1301, in render
    self.environment.handle_exception()
  File "D:\Python\Python39\Lib\site-packages\jinja2\environment.py", line 936, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "E:\dev\数据分析教程\01-如何分类西瓜\latex\template\simple.tplx", line 2, in top-level template code
    ((*- extends 'base.tplx' -*))
jinja2.exceptions.TemplateNotFound: base.tplx

Environment

  • OS: Windows 10 22H2
  • Python: 3.9.10
  • jinja2: 3.1.2
  • Jupyter version:
IPython          : 8.16.1
ipykernel        : 6.29.4
ipywidgets       : 8.1.0
jupyter_client   : 8.3.0
jupyter_core     : 5.3.1
jupyter_server   : 2.7.2
jupyterlab       : 4.0.5
nbclient         : 0.8.0
nbconvert        : 7.16.4
nbformat         : 5.9.2
notebook         : 6.1.0
qtconsole        : 5.5.1
traitlets        : 5.9.0

Additional Context

  • Templates are located in D:/Python/Python39/share/jupyter/nbconvert/templates/latex.
  • Attempted to manually specify template path using --template-path option without success.
  • Other templates like simple.tplx are located in E:/dev/数据分析教程/01-如何分类西瓜/latex/template/.

Any help in resolving this issue would be greatly appreciated.

@t-makaro
Copy link
Contributor

t-makaro commented Jun 6, 2024

Nbconvert hasn't used the .tplx extension since the version 5.x days. You will need to extend from base.tex.j2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants