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:
and jupyter output panel says:
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!
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:
sudo apt-get install texlive-xetex texlive-fonts-recommended texlive-latex-recommended
- Active env where you have jupyter installed
- Execute this command:
jupyter nbconvert --to pdf your_file.ipynb
If you are using arch linux or any child distro of arch,
❯ sudo pacman -S texlive-latexextra texlive-core
That fixed it for me
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.
Since I’m using conda venvs, I did these steps:
- Activate conda venv using:
conda activate <NAME_OF_VENV>
in Anaconda prompt.
- 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.
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
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.
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
When I try to export my Jupyter Notebook in pdf format in VSCode like this:
and jupyter output panel says:
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!
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:
sudo apt-get install texlive-xetex texlive-fonts-recommended texlive-latex-recommended
- Active env where you have jupyter installed
- Execute this command:
jupyter nbconvert --to pdf your_file.ipynb
If you are using arch linux or any child distro of arch,
❯ sudo pacman -S texlive-latexextra texlive-core
That fixed it for me
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.
Since I’m using conda venvs, I did these steps:
- Activate conda venv using:
conda activate <NAME_OF_VENV>
in Anaconda prompt. - 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.
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
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.
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