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

8

20

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!

Dunton answered 3/9, 2021 at 19:32 Comment(0)
D
13

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.

Dunton answered 8/2, 2022 at 8:15 Comment(0)
D
3

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

Durkee answered 3/9, 2021 at 19:57 Comment(2)
Thanks for your response. I saw that. But it didn't work for me. Please write your attempt in specifying steps.Dunton
I just update the answer. You can try thisDurkee
P
3

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.

Plainsman answered 27/1, 2022 at 2:42 Comment(0)
R
1

This worked for me without having to deal with the hassle of Python environment setup or installing latex:

  • Click export
  • Pick HTML
  • Open the HTML file in your web browser
  • Print the page, and it'll be formatted as a PDF file
Rosemaria answered 26/4 at 12:16 Comment(1)
yes, maybe it won't look as perfect, but at least you don't need a 5GB latex install just to export a notebook, ffsInaudible
G
0

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

❯ sudo pacman -S texlive-latexextra texlive-core

That fixed it for me

Gimpel answered 9/1, 2022 at 13:22 Comment(0)
M
0

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

Mesocarp answered 7/3, 2022 at 15:10 Comment(0)
S
0

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.

Softfinned answered 6/7, 2022 at 11:57 Comment(0)
B
0

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

Batory answered 16/10, 2022 at 15:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.