Parseltongue
Parseltongue

Reputation: 11657

Solving "500: Internal Server Error, nbconvert failed: xelatex not found in PATH"

Whenever I try to export a Jupyter notebook as a PDF I get the following error in a separate window:

500 : Internal Server Error The error was:

nbconvert failed: xelatex not found on PATH, if you have not installed xelatex you may need to do so. Find further instructions at https://nbconvert.readthedocs.io/en/latest/install.html#installing-tex.

I am running macOS Sierra 10.12.6.

Things I have tried:

Running

!echo $PATH

Yields:

/Users/ed/anaconda/bin:/Users/ed/anaconda/bin:/usr/bin:/bin:/usr/sbin:/sbin

I located the directory containing xelatex as per @einsweniger suggestion here: /usr/local/texlive/bin/x86_64-darwin. I copied and pasted XeLatex into the bin directory above, and get a new error:

nbconvert failed: PDF creating failed, captured latex output: warning: kpathsea: configuration file texmf.cnf not found in these directories: /Users/e/anaconda/bin:/Users/ed/anaconda/bin/share/texmf-local/web2c:/Users/ed/anaconda/bin/share/texmf-dist/web2c:/Users/ed/anaconda/bin/share/texmf/web2c:/Users/ed/anaconda/bin/texmf-local/web2c:/Users/ed/anaconda/bin/texmf-dist/web2c:/Users/ed/anaconda/bin/texmf/web2c:/Users/ed/anaconda:/Users/edefilippis/anaconda/share/texmf-local/web2c:/Users/e/anaconda/share/texmf-dist/web2c:/Users/ed/anaconda/share/texmf/web2c:/Users/ed/anaconda/texmf- This is XeTeX, Version 3.14159265-2.6-0.99999 (TeX Live 2018) (preloaded format=xelatex)

kpathsea: Running mktexfmt xelatex.fmt I can't find the format file `xelatex.fmt'!

I also put xelatex.fmt in the directory, but am still getting the error.

Upvotes: 59

Views: 181748

Answers (16)

christianbueno.1
christianbueno.1

Reputation: 592

On fedora 39.

To work with jupyter and create a pdf file. Install latex packages, you can use the medium in size option.

sudo dnf install texlive-scheme-medium

Upvotes: 0

Kamal AZIZ
Kamal AZIZ

Reputation: 19

The same problem ocures for me, I solved it by follwing these steps :

  1. downloading and installing miktex.
  2. close and restart jupyter
  3. test the export
  4. at the export, a message appears to confirm install of all dependencies (png export, enum, pdf, html-pdf.. => you just clic confirm and install

Link to download : miktex download

Note :

Upvotes: 1

Danial Shabbir
Danial Shabbir

Reputation: 650

In terminal type

$ sudo apt-get install texlive-xetex texlive-fonts-recommended texlive-plain-generic

just as Nico mentioned. run the following commands

$ export PATH=/Library/TeX/texbin:$PATH

to convert notebook to pdf run

$ jupyter nbconvert your_notebook.ipynb --to pdf

Upvotes: 18

Vini_OP
Vini_OP

Reputation: 1

Close all the anaconda runing programs and then,open conda command prompt and try the following command: conda install -c conda-forge pandoc

Upvotes: -1

eva bacas
eva bacas

Reputation: 83

I know this question is long answered, but I just ran into this issue and found a very easy, codeless solution: print to PDF.

Thought I might post this here for anyone else who doesn't feel like figuring out path variables or updating a zillion different things. Your browser's print function probably works just fine.

Upvotes: 4

Laksath Adityan M K
Laksath Adityan M K

Reputation: 17

Windows users can save the .ipynb file as a HTML file and print the HTML file to save it as PDF with custom settings.

Upvotes: 1

dembelet
dembelet

Reputation: 11

How to install latex and xelatex on Mac so that Jupyter "Download as PDF" will work

brew install pandoc
brew tap homebrew/cask
brew cask install basictex
eval "$(/usr/libexec/path_helper)"
# Update $PATH to include `/usr/local/texlive/2020basic/bin/x86_64-darwin`
sudo tlmgr update --self
sudo tlmgr install texliveonfly
sudo tlmgr install xelatex
sudo tlmgr install adjustbox
sudo tlmgr install tcolorbox
sudo tlmgr install collectbox
sudo tlmgr install ucs
sudo tlmgr install environ
sudo tlmgr install trimspaces
sudo tlmgr install titling
sudo tlmgr install enumitem
sudo tlmgr install rsfs

More info here

Upvotes: 1

Inevitable4
Inevitable4

Reputation: 9

If (You are using jupyter the easier way I found was to)

  • Download the file in latex.
  • Upload it to overleaf.
  • And then download it as a pdf

Else if ( You are using google collab)

  • Download as ipynb
  • Upload to jupyter and repeat the above steps.

Upvotes: 0

Supriya
Supriya

Reputation: 1

  1. Update/Reinstall Anaconda if not updated.
  2. now install chromium through link https://chromium.woolyss.com/download/en/ and make it default browser.
  3. Then run jupyter notebook using this browser.
  4. Lastly use option "Download as" in jupyter notebook and then select the option using PDF via pyppeteer (.html)

HOLA!! It worked..

Upvotes: -2

Sidrah Madiha Siddiqui
Sidrah Madiha Siddiqui

Reputation: 1364

Run this command in your jupyter terminal (or in your environment if you have any), close all jupyter notebook tabs and reopen it then convert the notebook to pdf

pip install --upgrade --user nbconvert

Upvotes: -1

Yaakov Bressler
Yaakov Bressler

Reputation: 12008

On mac, you can install mactex using homebrew with the following: brew install --cask mactex

Upvotes: 1

Henry Cooksley
Henry Cooksley

Reputation: 1

Add "env": {"PATH":"$PATH"} to your kernel.json, for me that was in /opt/anaconda3/share/jupyter/kernels/python3/kernel.json.

JupyterLab or Anaconda seems to override the system PATH by default, if you set this then the PATH will be the same in JupyterLab and in your shell, so if you have anything custom installed like xelatex, it will show up in JupyterLab.

Upvotes: 0

Nico
Nico

Reputation: 782

I encountered the same issue. As people previously stated, the problem lies in that xlatex isn't found in your PATH environment variable.

A solution that worked for me was to run the following from the notebook:

!export PATH=/Library/TeX/texbin:$PATH

Or in a command line simply:

export PATH=/Library/TeX/texbin:$PATH

And then run the export to pdf from a command line (within your virtual environment if there is one in place) as follows:

 jupyter nbconvert your_notebook.ipynb --to pdf

This should create a pdf of your notebook on the same directory it is running.

Upvotes: 40

IamSierraCharlie
IamSierraCharlie

Reputation: 534

I've run into similar issues in the past with paths in python when using tensorflow in Windows and Linux. As is pointed out by others, using PATH is the way to go (i.e update in .bashrc if it was linux), but I've found the code below to resolve path issues on a script by script basis.

import sys
if "\your\path\to\xelatex" not in sys.path:
    print('adding path') # I just add this to know if the path was present or not.
    sys.path.append("\your\path\to\xelatex")

essentially would check PATH for what it is you are looking for and then adds it if it is missing. You probably don't even need the 'if' statement.
Perhaps not the most practical way has worked well for me where I know the path in question is perhaps a 'rarely used' or 'one time use' PATH add...

So as was pointed out in comments above (and I think you already have) find the location of the file and add its location using the above code.

Some more reading on it: https://docs.python.org/3/tutorial/modules.html 6.2 Standard Modules

Upvotes: 2

einsweniger
einsweniger

Reputation: 611

I'm not accustomed with Mac install paths, from what the basictex faq says, I gather the executeables should live in /usr/local/texlive/bin/x86_64-darwin Running which xelatex in a terminal might also help finding where the command is, but that only works if the directory is already in your PATH variable.

Another method would be running find / -name 'xelatex' if it is not within your PATH so you might find it that way (might take a while as this will search you whole harddrive).

Once you've found it and added the path to your PATH variable, you should also check if the jupyter has the correct PATH by running

import os
print(os.environ['PATH'])

within a notebook.

Upvotes: 10

user12867493
user12867493

Reputation:

If there is an update available maybe try and update Jupyter

Upvotes: -1

Related Questions