pythonpdfjupyter-notebookfile-conversionoserror

Converting Python notebook to PDF using nbconvert


I am trying to convert my python notebook to pdf using:

from google.colab import drive
drive.mount('/content/gdrive')

import os
os.chdir("/content/gdrive/MyDrive/Colab Notebooks/")

!jupyter nbconvert --to pdf Project_2.ipynb

I am using Google colabs notebooks, https://colab.research.google.com/. But I am getting this error while conversion:

Error:

OSError: 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.

How can I install Miktex on Google colabs or any way to resolve it?

Any help will be really appreciated.


Solution

  • I think you have to install other required packages to unlock the full capabilities of nbconvert:

    from google.colab import drive
    drive.mount('/content/gdrive')
    
    import os
    os.chdir("/content/gdrive/MyDrive/Colab Notebooks/")
    
    !apt-get install texlive-xetex texlive-fonts-recommended texlive-plain-generic
    
    !jupyter nbconvert --to pdf Project_2.ipynb
    

    More info can be found here. There are other packages that may be needed, you can find those too at the linked documentation.