Error saving to PDF from Jupyter Notebook

When I try to save my Jupyter Notebook as PDF, I get an "500 : Internal Server Error". Any ideas on how to fix that?

4 Answers

The basic steps to correctly setup nbconvert to convert ipython notebooks to pdf/latex are

  1. Install nbconvert
  2. Install pandoc
  3. Install Texlive

Installing nbconvert

pip install nbconvert

or conda install nbconvert

Installing pandoc

sudo apt-get install pandoc for Ubuntu

Installing texlive

You can install recommended packages or full install.

sudo apt-get install texlive texlive-xetex texlive-fonts-recommended texlive-generic-extra texlive-generic-recommended

`

To full install texlive follow the instructions given at tug. I downloaded tar.gz file from tug-texlive-download and followed instructions given at TeX Live - Quick install. Installation instructions in summary:

  1. Clean up

    rm -rf /usr/local/texlive/2019

    rm -rf ~/.texlive2019

  2. Run installer

    unpack the zip file

    cd /your/unpacked/directory

    perl install-tl

    Enter command: i

  3. Setting path

    sudo vi /etc/bash.bashrc and insert

    PATH=/usr/local/texlive/2019/bin/x86_64-linux:$PATH; export PATH

    MANPATH=/usr/local/texlive/2019/texmf-dist/doc/man:$MANPATH; export MANPATH

    INFOPATH=/usr/local/texlive/2019/texmf-dist/doc/info:$INFOPATH; export INFOPATH

  4. Setting default papersize

    tlmgr paper letter

If you have LaTeX installed you can download as PDF directly from Jupyter notebook with File -> Download as -> PDF via LaTeX (.pdf). Otherwise follow these two steps.

  1. Convert the Jupyter notebook file to html. Select File -> Download as -> HTML (.html) or run the following command:

    jupyter nbconvert --to html notebook.ipynb 

    This will convert the Jupyter document file notebook.ipynb into the html output format.

    Google Colaboratory is Google's free Jupyter notebook environment that requires no setup and runs entirely in the cloud. If you are using Google Colab the commands are the same, but Google Colab only lets you download .ipynb or .py formats.

  2. Install wkhtmltopdf command line utility to convert html to pdf using sudo apt install wkhtmltopdf and convert the html file notebook.html into a pdf file called notebook.pdf.

    wkhtmltopdf notebook.html notebook.pdf 

The most probable cause, is that you have not installed the appropriate dependencies. Your Ubuntu system has to have some packages installed regarding conversion of LaTeX and XeTeX files, in order to save your notebook as PDF. You can install them by:

sudo apt-get install texlive texlive-xetex texlive-generic-extra texlive-generic-recommended pandoc

Also, nbconvert is another dependency that is usually automatically installed with jupyter. But you can install it just to be sure, while having your virtual environment activated:

pip install -U nbconvert

I was able to fix this issue by eliminating any spaces between my LaTeX code and the $. For example: $\frac instead of $ \frac

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like