nbconvert icon indicating copy to clipboard operation
nbconvert copied to clipboard

Nbconvert failed index.tex.j2

Open LeTrongDat opened this issue 4 years ago • 21 comments

I followed the instructions in this documentation: https://nbconvert.readthedocs.io/_/downloads/en/5.2.1/pdf/. But when I use jupyter nbconvert --to pdf Mynotebook.ipynb I get the error Screen Shot 2020-11-11 at 20 12 38

LeTrongDat avatar Nov 11 '20 13:11 LeTrongDat

Template names have been renamed since nbconvert 6.0: .tplx extension has been replaced by .tex.j2. Your installation seems inconsistant.

You may try to upgrade your nbconvert version to >= 6.0, for example using:

pip install -U nbconvert

boileaum avatar Nov 12 '20 16:11 boileaum

I tried the pip install -U nbconvert but it didn't work. I'm getting a similar error File "C:\ProgramData\Anaconda3\lib\site-packages\jinja2\loaders.py", line 497, in load raise TemplateNotFound(name) jinja2.exceptions.TemplateNotFound: index.tex.j2

agustingu avatar Nov 12 '20 18:11 agustingu

Screen Shot 2020-11-13 at 01 41 33 This is nbconvert version on my laptop. But it still doesn't work.

LeTrongDat avatar Nov 12 '20 18:11 LeTrongDat

Did you test this in a virtual environment? May be some versions of jupyter packages and nbconvert are not compatible in your current installation.

boileaum avatar Nov 16 '20 08:11 boileaum

You may test this:

boileau@m-boileau:   ~$ cd /tmp
boileau@m-boileau:   /tmp$ mkdir this
boileau@m-boileau:   /tmp$ cd this
boileau@m-boileau:   /tmp/this$ virtualenv .venv
created virtual environment CPython3.7.9.final.0-64 in 337ms
  creator CPython3Posix(dest=/private/tmp/this/.venv, clear=False, global=False)
  seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/Users/boileau/Library/Application Support/virtualenv)
    added seed packages: pip==20.2.4, setuptools==50.3.2, wheel==0.35.1
  activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator
boileau@m-boileau:   /tmp/this$ source .venv/bin/activate
(.venv) boileau@m-boileau:   /tmp/this$ pip install jupyter
Collecting jupyter
  Using cached jupyter-1.0.0-py2.py3-none-any.whl (2.7 kB)
Collecting nbconvert
  Using cached nbconvert-6.0.7-py3-none-any.whl (552 kB)
[...]
(.venv) boileau@m-boileau:   /tmp/this$ jupyter-nbconvert --version
6.0.7
(.venv) boileau@m-boileau:   /tmp/this$ cat >this.ipynb <<EOL
{ 
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import this"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
EOL
(.venv) boileau@m-boileau:   /tmp/this$ export JUPYTER_CONFIG_DIR='.'
(.venv) boileau@m-boileau:   /tmp/this$ jupyter-nbconvert --to html this.ipynb 
[NbConvertApp] Converting notebook this.ipynb to html
[NbConvertApp] Writing 567061 bytes to this.html
(.venv) boileau@m-boileau:   /tmp/this$ 

These bash commands:

  • create and activate a virtualenv
  • install jupyter using pip
  • create a minimal python notebook
  • exclude default JUPYTER_CONFIG_DIR to prevent from loading personal settings
  • convert notebook to html

Works well on my Mac.

boileaum avatar Nov 17 '20 15:11 boileaum

Same issue here.

sean-reed avatar Nov 17 '20 23:11 sean-reed

Me too.

domokane avatar Jan 15 '21 19:01 domokane

Me too

BioTechTimy avatar Jan 30 '21 00:01 BioTechTimy

+1

DeanHuang-Git avatar Feb 02 '21 20:02 DeanHuang-Git

Same here

In the meantime, my workaround was installing MikTex (since I'm on Windows) and then installing jupyter in a virtual environment and exporting a latex file from jupyter notebooks.

Then I ran the following command from powershell:

xelatex 'Put your file name here'

Here's another alternative, it seems basically the same as converting to html and then using the print-> save as pdf feature: https://towardsdatascience.com/jupyter-notebook-to-pdf-in-a-few-lines-3c48d68a7a63

You can also export as markdown and then convert it following this page's instructions: https://gist.github.com/justincbagley/ec0a6334cc86e854715e459349ab1446

amartinson193 avatar Feb 27 '21 19:02 amartinson193

Same issue with nbconvert

image

Python 3.9.1, pip 21.01.1

Is it normal that when I launch ''pip install nbconvert'' there is nothing in the ''templates'' directory?

carobizbiz avatar Mar 02 '21 20:03 carobizbiz

Is this with a conda environment, a virtual environment, or system python? It seems like templates are not getting installed alongside the library through some installation path.

Is it normal that when I launch ''pip install nbconvert'' there is nothing in the ''templates'' directory?

No it should have templates present in your environment's share/jupyter/nbconvert/templates/ directory. I just tried a fresh 3.9 venv and didn't hit any issues installing nbconvert with pip.

MSeal avatar Mar 03 '21 07:03 MSeal

No it should have templates present in your environment's share/jupyter/nbconvert/templates/ directory. I just tried a fresh 3.9 venv and didn't hit any issues installing nbconvert with pip.

I found the templates eventually in my ''C:/users/.../AppData/Roaming/Python/share/jupyter/nbconvert''. The nbconvert log never specified this path in its degub.

Copy pasting the templates in ''C:/users/.../AppData/Roaming/jupyter/nbconvert'' solved the issue for me.

I don't understand why the Roaming/Python/jupyter folder is not found when I launch nbconvert, and vice versa why this Roaming/jupyter folder exists.

carobizbiz avatar Mar 03 '21 15:03 carobizbiz

No it should have templates present in your environment's share/jupyter/nbconvert/templates/ directory. I just tried a fresh 3.9 venv and didn't hit any issues installing nbconvert with pip.

I found the templates eventually in my ''C:/users/.../AppData/Roaming/Python/share/jupyter/nbconvert''. The nbconvert log never specified this path in its degub.

Copy pasting the templates in ''C:/users/.../AppData/Roaming/jupyter/nbconvert'' solved the issue for me.

I don't understand why the Roaming/Python/jupyter folder is not found when I launch nbconvert, and vice versa why this Roaming/jupyter folder exists.

I tried this approach to download pdf via latex but I'm getting the error below:

nbconvert failed: PDF creating failed, captured latex output:
Failed to run "xelatex notebook.tex -quiet" command:
C:\Users\username\AppData\Local\Programs\MiKTeX 2.9\tex/generic/oberdiek\
ifvtex.sty:170: 
C:\Users\username\AppData\Local\Programs\MiKTeX 2.9\tex/latex/hyperref\hy
perref.sty:2946: Extra 
notebook.tex:66: Extra 
notebook.tex:66: Extra 
notebook.tex:66: Extra 
notebook.tex:66: Extra 
notebook.tex:66: Extra 
^^@:66: Emergency stop

has anyone had the same issue? I think it's relate to latex itself. Since I could download the zip and run it and compile it on overleaf.

agustingu avatar Mar 04 '21 14:03 agustingu

me too

Python 3.9 from MS Store

jupyter core : 4.7.1 jupyter-notebook : 6.3.0 qtconsole : 5.0.3 ipython : 7.22.0 ipykernel : 5.5.3 jupyter client : 6.1.12 jupyter lab : 3.0.14 nbconvert : 6.0.7 ipywidgets : 7.6.3 nbformat : 5.1.3 traitlets : 5.0.5

Kri-Ol avatar Apr 26 '21 22:04 Kri-Ol

Still having this issue too. Fresh install's inside a virtual environment do not help. I must specify nbconvert==5.6.1 in requirements.txt file to get it to function.

nleroy917 avatar Feb 12 '22 16:02 nleroy917

For the linux user:

I am inspired by the method proposed by carobizbiz, there must be some missing template files in the directory where the command jupyter nbconvert --to xxx --template xxx tries to get access. If we can find the directory contains the template files and copy-paste them into the target directory, the problem should be solved.

❯ python --version
Python 3.10.8
❯ jupyter --version
Selected Jupyter core packages...
IPython          : 8.4.0
ipykernel        : 6.15.2
ipywidgets       : 8.0.2
jupyter_client   : 7.3.5
jupyter_core     : 4.11.1
jupyter_server   : 1.18.1
jupyterlab       : 3.4.8
nbclient         : 0.6.7
nbconvert        : 7.0.0
nbformat         : 5.4.0
notebook         : 6.4.12
qtconsole        : 5.3.2
traitlets        : 5.3.0

I used a virtual environment with the last proper functioning version nbconvert == 5.6.1 and did some experimental tricks and finally found out the location of these files in the non-virtual python environment: /lib/share/jupyter/nbconvert/templates/latex, which should be a generic path for linux systems.

image

The target folder for the command line should be /lib/YOUT_PYTHON_VERSION/site-packages/nbconvert/templates (e.g. the path on my machine is: /lib/python3.10/site-packages/nbconvert/templates. Correct me if yours is different). Then COPY + PASTE all the template files from the first path into this (almost) empty one with GUI or Terminal.

image

Then your command line jupyter nbconvert --to xxx --template xxx shoud work now, at least on my machine, it went as well as nbconvert <= 5.6.1

wang-yiwei avatar Oct 14 '22 10:10 wang-yiwei

Same issue here

j-bowhay avatar Apr 20 '23 20:04 j-bowhay

I'm having the same issue. I tried using both a virtual environment (with Poetry) and a system-wide installation.

In the virtual environment, I see the templates in .venv/share/jupyter/nbconvert/templates In the system-wide installation I see them in /usr/share/jupyter/nbconvert/templates

However none of these work and I'm getting the same error as others. I tried copying them to /usr/lib/python3/dist-packages/nbconvert/templates and to /usr/local/lib/python3.10/dist-packages/nbconvert/templates

I also the in the virtual environment to .venv/lib/python3.10/dist-packages/nbconvert/templates and running the command with a venv shell but no matter what I try I always get the error TemplateNotFound(name) jinja2.exceptions.TemplateNotFound: index.tex.j2

geeshta avatar May 09 '23 14:05 geeshta

Same issue

lan2720 avatar Aug 07 '23 09:08 lan2720

same issue

YousraH avatar Sep 13 '24 14:09 YousraH