pythonvisual-studio-codejupyter-notebookexport-to-pdf

How to Export Jupyter Notebook by VSCode in PDF format? (Windows 10)


When I try to export my Jupyter Notebook in pdf format in VSCode like this: enter image description here

enter image description here

then I got this error:

Export failed. Please check the 'Jupyter' output panel for further details.

and jupyter output panel says:

[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 https://nbconvert.readthedocs.io/en/latest/install.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.

so i tried to install MikTeX and update the required packages, but still I can't export Jupyter Notebooks in PDF format by VSCode!
how can I fix this problem?

Note That I know i can do it by convert it to HTML and then with ctrl+p try to save it as pdf! but I want to convert it to pdf in straight way!


Solution

  • Since I'm using conda venvs, I did these steps:

    1. Activate conda venv using: conda activate <NAME_OF_VENV> in Anaconda prompt.
    2. Install nbconvert using conda install -c anaconda nbconvert

    Now it's all okay, and I can export Jupyter notebooks in HTML and PDF format both.

    Update 11/17/2023

    nbconvert is compatible with Python 3.8-3.11 based on the official doc.