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
- Install nbconvert
- Install pandoc
- 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:
Clean up
rm -rf /usr/local/texlive/2019rm -rf ~/.texlive2019Run installer
unpack the zip file
cd /your/unpacked/directoryperl install-tlEnter command: i
Setting path
sudo vi /etc/bash.bashrcand insertPATH=/usr/local/texlive/2019/bin/x86_64-linux:$PATH; export PATHMANPATH=/usr/local/texlive/2019/texmf-dist/doc/man:$MANPATH; export MANPATHINFOPATH=/usr/local/texlive/2019/texmf-dist/doc/info:$INFOPATH; export INFOPATHSetting 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.
Convert the Jupyter notebook file to html. Select File -> Download as -> HTML (.html) or run the following command:
jupyter nbconvert --to html notebook.ipynbThis 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.
Install wkhtmltopdf command line utility to convert html to pdf using
sudo apt install wkhtmltopdfand 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 pandocAlso, 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