admin管理员组文章数量:1403506
I have encountered an issue when trying to export jupyter notebooks that contains any form of text in "Markdown cells". The export is succesful IF the notebook only contains "code cells".
Some background info:
- I'm using Jupyter Notebook through VSCode
- Before launching a new notebook I set up a virtual environment in the workspace folder following this:
$ python -m venv projectname
$ source projectname/bin/activate
(venv) $ pip install ipykernel
(venv) $ ipython kernel install --user --name=projectname
3)I mainly use two packages (handcalcs, forallpeople) which are used to render code/equations to Latex in the notebooks, which works fine.
4) To make .html/pdf export work I had to follow this solution
5) I have installed MacTex.
Some snippet of the error:
File "/Users/~/Desktop/Projekt_01/VENV_Testprojekt_01/lib/python3.11/site-packages/nbconvert/utils/pandoc.py", line 75, in get_pandoc_version raise PandocMissing() nbconvert.utils.pandoc.PandocMissing: Pandoc wasn't found. Please check that pandoc is installed: .html [NbConvertApp] Exiting application: jupyter-nbconvert
and later
[error] If you have not installed xelatex (TeX), you will need to do so before you can export to PDF. For further instructions, please see .html#installing-tex.
But I do have pandoc installed
(VENV_Testprojekt_01) (base) User-MacBook-Pro:Projekt_01 User$ pip install pandoc --upgrade
Requirement already satisfied: pandoc in ./VENV_Testprojekt_01/lib/python3.11/site-packages (2.4)
Requirement already satisfied: plumbum in ./VENV_Testprojekt_01/lib/python3.11/site-packages (from pandoc) (1.9.0)
Requirement already satisfied: ply in ./VENV_Testprojekt_01/lib/python3.11/site-packages (from pandoc) (3.11)
Originally, I encountered the exact same issue (i.e. notebook could only be PDF exported if it did not contained ANY Markdown cells) when picking a .conda virtual environment though VSCode's interface. The required fix here was simply to install XeLateX through a MacTeX installation.
I therefore think the issue is that my virtual environment is unable to "see" my TeX installation somehow? I did try to type export PATH=/Library/TeX/texbin:$PATH
in the .venv terminal, but it did not fix the issue.
I've tried to find a solution for a while now searching different threads without luck. Hope you can help a n00b.. :)
Full error / output snippet for reference:
Screenshot of Jupyter Notebook
1:43:21.176 [info] Process Execution: ~/Desktop/Projekt_01/VENV_Testprojekt_01/bin/python -m jupyter nbconvert /var/folders/t8/m50k_bzj2192djbf82ktcs7m0000gn/T/309c31b7-bc08-48d9-9cc9-192658764c4f/TestExportPDF.ipynb --to pdf --output tmp-77052zEl8kSV0be6y.pdf --output-dir /var/folders/t8/m50k_bzj2192djbf82ktcs7m0000gn/T --debug
21:43:24.744 [error] Export failed [Error: [NbConvertApp] Searching ['/Users/~/.jupyter', '/Users/~/Desktop/Projekt_01/VENV_Testprojekt_01/etc/jupyter', '/usr/local/etc/jupyter', '/etc/jupyter'] for config files
[NbConvertApp] Looking for jupyter_config in /etc/jupyter
[NbConvertApp] Looking for jupyter_config in /usr/local/etc/jupyter
[NbConvertApp] Looking for jupyter_config in /Users/~/Desktop/Projekt_01/VENV_Testprojekt_01/etc/jupyter
[NbConvertApp] Looking for jupyter_config in /Users/~/.jupyter
[NbConvertApp] Looking for jupyter_nbconvert_config in /etc/jupyter
[NbConvertApp] Looking for jupyter_nbconvert_config in /usr/local/etc/jupyter
[NbConvertApp] Looking for jupyter_nbconvert_config in /Users/~/Desktop/Projekt_01/VENV_Testprojekt_01/etc/jupyter
[NbConvertApp] Looking for jupyter_nbconvert_config in /Users/~/.jupyter
[NbConvertApp] Looping through config variables with prefix "JUPYTER_NBCONVERT"
[NbConvertApp] Converting notebook /var/folders/t8/m50k_bzj2192djbf82ktcs7m0000gn/T/309c31b7-bc08-48d9-9cc9-192658764c4f/TestExportPDF.ipynb to pdf
[NbConvertApp] Notebook name is 'tmp-77052zEl8kSV0be6y'
[NbConvertApp] Template paths:
/Users/~/Library/Jupyter/nbconvert/templates/latex
/Users/~/Desktop/Projekt_01/VENV_Testprojekt_01/share/jupyter/nbconvert/templates/latex
/usr/local/share/jupyter/nbconvert/templates/latex
/Users/~/Desktop/Projekt_01/VENV_Testprojekt_01/share/jupyter/nbconvert/templates/base
/Users/~/Library/Jupyter
/Users/~/Library/Jupyter/nbconvert/templates
/Users/~/Library/Jupyter/nbconvert/templates/compatibility
/Users/~/Desktop/Projekt_01/VENV_Testprojekt_01/share/jupyter
/Users/~/Desktop/Projekt_01/VENV_Testprojekt_01/share/jupyter/nbconvert/templates
/Users/~/Desktop/Projekt_01/VENV_Testprojekt_01/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
/Users/~/Library/Jupyter/nbconvert/templates
/Users/~/Desktop/Projekt_01/VENV_Testprojekt_01/share/jupyter/nbconvert/templates
/usr/local/share/jupyter/nbconvert/templates
[NbConvertApp] Applying preprocessor: TagRemovePreprocessor
[NbConvertApp] Applying preprocessor: RegexRemovePreprocessor
[NbConvertApp] Applying preprocessor: SVG2PDFPreprocessor
[NbConvertApp] Applying preprocessor: LatexPreprocessor
[NbConvertApp] Applying preprocessor: HighlightMagicsPreprocessor
[NbConvertApp] Applying preprocessor: ExtractOutputPreprocessor
[NbConvertApp] Applying preprocessor: ExtractAttachmentsPreprocessor
[NbConvertApp] Attempting to load template index.tex.j2
[NbConvertApp] template_paths: /Users/~/Library/Jupyter/nbconvert/templates/latex:/Users/~/Desktop/Projekt_01/VENV_Testprojekt_01/share/jupyter/nbconvert/templates/latex:/usr/local/share/jupyter/nbconvert/templates/latex:/Users/~/Desktop/Projekt_01/VENV_Testprojekt_01/share/jupyter/nbconvert/templates/base:/Users/~/Library/Jupyter:/Users/~/Library/Jupyter/nbconvert/templates:/Users/~/Library/Jupyter/nbconvert/templates/compatibility:/Users/~/Desktop/Projekt_01/VENV_Testprojekt_01/share/jupyter:/Users/~/Desktop/Projekt_01/VENV_Testprojekt_01/share/jupyter/nbconvert/templates:/Users/~/Desktop/Projekt_01/VENV_Testprojekt_01/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:/Users/~/Library/Jupyter/nbconvert/templates:/Users/~/Desktop/Projekt_01/VENV_Testprojekt_01/share/jupyter/nbconvert/templates:/usr/local/share/jupyter/nbconvert/templates
[NbConvertApp] ERROR | Error while converting '/var/folders/t8/m50k_bzj2192djbf82ktcs7m0000gn/T/309c31b7-bc08-48d9-9cc9-192658764c4f/TestExportPDF.ipynb'
Traceback (most recent call last):
File "/Users/~/Desktop/Projekt_01/VENV_Testprojekt_01/lib/python3.11/site-packages/nbconvert/nbconvertapp.py", line 487, in export_single_notebook
output, resources = self.exporter.from_filename(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/~/Desktop/Projekt_01/VENV_Testprojekt_01/lib/python3.11/site-packages/nbconvert/exporters/templateexporter.py", line 390, in from_filename
return super().from_filename(filename, resources, **kw) # type:ignore[return-value]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/~/Desktop/Projekt_01/VENV_Testprojekt_01/lib/python3.11/site-packages/nbconvert/exporters/exporter.py", line 201, in from_filename
return self.from_file(f, resources=resources, **kw)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/~/Desktop/Projekt_01/VENV_Testprojekt_01/lib/python3.11/site-packages/nbconvert/exporters/templateexporter.py", line 396, in from_file
return super().from_file(file_stream, resources, **kw) # type:ignore[return-value]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/~/Desktop/Projekt_01/VENV_Testprojekt_01/lib/python3.11/site-packages/nbconvert/exporters/exporter.py", line 220, in from_file
return self.from_notebook_node(
^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/~/Desktop/Projekt_01/VENV_Testprojekt_01/lib/python3.11/site-packages/nbconvert/exporters/pdf.py", line 184, in from_notebook_node
latex, resources = super().from_notebook_node(nb, resources=resources, **kw)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/~/Desktop/Projekt_01/VENV_Testprojekt_01/lib/python3.11/site-packages/nbconvert/exporters/latex.py", line 92, in from_notebook_node
return super().from_notebook_node(nb, resources, **kw)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/~/Desktop/Projekt_01/VENV_Testprojekt_01/lib/python3.11/site-packages/nbconvert/exporters/templateexporter.py", line 429, in from_notebook_node
output = self.template.render(nb=nb_copy, resources=resources)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/~/Desktop/Projekt_01/VENV_Testprojekt_01/lib/python3.11/site-packages/jinja2/environment.py", line 1295, in render
self.environment.handle_exception()
File "/Users/~/Desktop/Projekt_01/VENV_Testprojekt_01/lib/python3.11/site-packages/jinja2/environment.py", line 942, in handle_exception
raise rewrite_traceback_stack(source=source)
File "/Users/~/Desktop/Projekt_01/VENV_Testprojekt_01/share/jupyter/nbconvert/templates/latex/index.tex.j2", line 8, in top-level template code
((* extends cell_style *))
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/~/Desktop/Projekt_01/VENV_Testprojekt_01/share/jupyter/nbconvert/templates/latex/style_jupyter.tex.j2", line 176, in top-level template code
\prompt{(((prompt)))}{(((prompt_color)))}{(((execution_count)))}{(((extra_space)))}
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/~/Desktop/Projekt_01/VENV_Testprojekt_01/share/jupyter/nbconvert/templates/latex/base.tex.j2", line 7, in top-level template code
((*- extends 'document_contents.tex.j2' -*))
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/~/Desktop/Projekt_01/VENV_Testprojekt_01/share/jupyter/nbconvert/templates/latex/document_contents.tex.j2", line 51, in top-level template code
((*- block figure scoped -*))
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/~/Desktop/Projekt_01/VENV_Testprojekt_01/share/jupyter/nbconvert/templates/latex/display_priority.j2", line 5, in top-level template code
((*- extends 'null.j2' -*))
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/~/Desktop/Projekt_01/VENV_Testprojekt_01/share/jupyter/nbconvert/templates/latex/null.j2", line 30, in top-level template code
((*- block body -*))
File "/Users/~/Desktop/Projekt_01/VENV_Testprojekt_01/share/jupyter/nbconvert/templates/latex/base.tex.j2", line 241, in block 'body'
((( super() )))
File "/Users/~/Desktop/Projekt_01/VENV_Testprojekt_01/share/jupyter/nbconvert/templates/latex/null.j2", line 32, in block 'body'
((*- block any_cell scoped -*))
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/~/Desktop/Projekt_01/VENV_Testprojekt_01/share/jupyter/nbconvert/templates/latex/null.j2", line 85, in block 'any_cell'
((*- block markdowncell scoped-*)) ((*- endblock markdowncell -*))
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/~/Desktop/Projekt_01/VENV_Testprojekt_01/share/jupyter/nbconvert/templates/latex/document_contents.tex.j2", line 68, in block 'markdowncell'
((( cell.source | citation2latex | strip_files_prefix | convert_pandoc('markdown+tex_math_double_backslash', 'json',extra_args=[]) | resolve_references | convert_explicitly_relative_paths | convert_pandoc('json','latex'))))
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/~/Desktop/Projekt_01/VENV_Testprojekt_01/lib/python3.11/site-packages/nbconvert/filters/pandoc.py", line 36, in convert_pandoc
return pandoc(source, from_format, to_format, extra_args=extra_args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/~/Desktop/Projekt_01/VENV_Testprojekt_01/lib/python3.11/site-packages/nbconvert/utils/pandoc.py", line 50, in pandoc
check_pandoc_version()
File "/Users/~/Desktop/Projekt_01/VENV_Testprojekt_01/lib/python3.11/site-packages/nbconvert/utils/pandoc.py", line 98, in check_pandoc_version
v = get_pandoc_version()
^^^^^^^^^^^^^^^^^^^^
File "/Users/~/Desktop/Projekt_01/VENV_Testprojekt_01/lib/python3.11/site-packages/nbconvert/utils/pandoc.py", line 75, in get_pandoc_version
raise PandocMissing()
nbconvert.utils.pandoc.PandocMissing: Pandoc wasn't found.
Please check that pandoc is installed:
.html
[NbConvertApp] Exiting application: jupyter-nbconvert
at xf.executeCommand (/Users/~/.vscode/extensions/ms-toolsai.jupyter-2025.2.0-darwin-x64/dist/extension.node.js:318:9552)
at async n0.export (/Users/~/.vscode/extensions/ms-toolsai.jupyter-2025.2.0-darwin-x64/dist/extension.node.js:319:412)
at async xb.performNbConvertExport (/Users/~/.vscode/extensions/ms-toolsai.jupyter-2025.2.0-darwin-x64/dist/extension.node.js:321:2500)
at async xb.performExport (/Users/~/.vscode/extensions/ms-toolsai.jupyter-2025.2.0-darwin-x64/dist/extension.node.js:321:2190)
at async xb.expor~pl (/Users/~/.vscode/extensions/ms-toolsai.jupyter-2025.2.0-darwin-x64/dist/extension.node.js:321:1798)
at async xb.export (/Users/~/.vscode/extensions/ms-toolsai.jupyter-2025.2.0-darwin-x64/dist/extension.node.js:321:1530)
at async T0.export (/Users/~/.vscode/extensions/ms-toolsai.jupyter-2025.2.0-darwin-x64/dist/extension.node.js:379:3134)
at async Sw.h (file:///Applications/Visual%20Studio%20Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:112:41551)]
21:43:24.744 [error] If you have not installed xelatex (TeX), you will need to do so before you can export to PDF. For further instructions, please see .html#installing-tex.
To avoid installing xelatex (TeX), you might want to try exporting to HTML and using your browser's "Print to PDF" feature.
If I simply delete the markdown cell, the export is succesful with ouput:
1:46:05.637 [info] Process Execution: ~/Desktop/Projekt_01/VENV_Testprojekt_01/bin/python -m jupyter nbconvert /var/folders/t8/m50k_bzj2192djbf82ktcs7m0000gn/T/60ba0d7a-dfca-484f-bd08-9bb715c2554a/TestExportWithMarkdown.ipynb --to pdf --output tmp-77052jGI4nYLX7kcy.pdf --output-dir /var/folders/t8/m50k_bzj2192djbf82ktcs7m0000gn/T --debug
本文标签: ipythonPDF export error when using Markdown cells in Jupyter NotebookStack Overflow
版权声明:本文标题:ipython - PDF export error when using Markdown cells in Jupyter Notebook - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744321894a2600541.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论