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

Question:

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:
enter image description here

and jupyter output panel says:
enter image description here

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!

Asked By: Shayan

||

Answers:

You can try following URL. Hope it will solve your issue

https://code.visualstudio.com/docs/datascience/jupyter-notebooks#_export-your-jupyter-notebook

I just tried in Linux(Ubuntu 20.04) and it worked for me

You can follow this steps:

  1. sudo apt-get install texlive-xetex texlive-fonts-recommended texlive-latex-recommended
  2. Active env where you have jupyter installed
  3. Execute this command: jupyter nbconvert --to pdf your_file.ipynb

Output:
enter image description here

Answered By: Sabil

If you are using arch linux or any child distro of arch,

❯ sudo pacman -S texlive-latexextra texlive-core

That fixed it for me

Answered By: K.vish

While this question has been answered twice neither one of the answers seemed to address the question on OP’s OS. I wanted to setup the same thing for a more streamlined workflow on Windows Jupyter development.

Unfortunately, I have been unabled to get the export as PDF button to work due to not knowing how to get VS Code to search the correct locations for the various dependencies; however, I have found a work around that allows one to export as PDF on Windows through WSL (Windows Subsystem for Linux).

WSL is a tool that I have grown to love using during all my development both professionally and within school, so I am sure you can find great use for it outside of PDF export if you do not already have it installed.

This method primarily uses the command line method for exporting using jupyter nbconvert --to pdf <filename>

This can also be used in Windows powershell; however, I have had little luck setting up the dependencies in powershell.

In WSL you can run this command and use the friendly neighbourhood Linux command line to install all the required dependencies.

Here is the documentation on how to setup nbconvert for Linux which I also found to work on WSL (https://nbconvert.readthedocs.io/en/latest/install.html)

If there are any other dependencies missing it is typically fairly easy to figure out how to install these through the command line.

Answered By: Chase McDougall

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

Also, you should consider that nbconvert is compatible with Python 3.7-3.9 based on the official doc.

Answered By: Shayan

Using anaconda for virtual environments on linux (Ubuntu 21.10), I needed to install these packages within the venv:

conda activate <NAME_OF_VENV>
pip install notebook
conda install nbconvert
conda install pandoc
conda deactivate

I already had texlive installed, but I was missing the xetex packages:

sudo apt install texlive-xetex

These were all required for me, as stated by the error messages given by VSCode

Answered By: Alexey Zagalsky

I am using a Debian distribution installed in Windows Subsystem Linux 2 with a Conda environment with a 3.7 Python version. I found the following error in the jupyter output while exporting a jupyter file:

! LaTeX Error: File `ucharcat.sty' not found

I solved the issue just by upgrading the Debian distribution from Debian 9 (strecht) to bullseye and re-installing latex in the upgraded distribution.

I found that the Windows Store installs Debian 9 (still in 2022) by default and therefore the LaTex version installed with the apt tool package dates from 2016. Perhaps there is a compatibility issue with Python 3.7 and the nbconvert package used to export to pdf files.

The code I used to

  • Check my Linux, and LaTex versions
  • Upgrade the Debian WSL distro
  • Uninstall and re-install LaTex

can be found in the following link

I hope this answer helps.

Answered By: eliasmaxil

I met the same problem… But I fixed it by simply using pip install jupyter_contrib_nbextensions according to the output panel (and I already have texlive installed in my win environment b

Answered By: PunkPeter