2

I'm trying to use lcapy's python library to draw some electrical circuits in google colab. Unfortunately, I'm always getting an error:

RuntimeError: pdflatex is not installed

Even though I did pip install pdflatex I couldn't find anything related to this error in lcapy's docs.

the notebook can be found here

chendoy
  • 155
  • 1
  • 2
  • 12
  • I think that some permission with you notebook is wrong, I can't open it. Anyway, are you sure pdflatex has been installed correctly? Did you do `pip install pdflatex`? It seems to be installed correctly in my Colab – SilentCloud Apr 12 '21 at 12:10
  • updated the link. and yes, I did ```pip install pdflatex```. it looks like colab does not recognize this library. – chendoy Apr 12 '21 at 12:13

2 Answers2

2

I experienced a similar issue/error trying to render PDFs from latex output generated by pandas in google colab recently. The error I got was complaining about a file (Error Code 2), listed 'pdflatex' as the missing file, but I confirmed the install had completed as you reported. This led me to realize there were missing LaTex dependencies that were generating the error; the traceback seemed a bit misleading to me. Here is the solution that worked for me:

First, install components and dependencies in colab notebook:

!pip install folium==0.2.1
!pip install pdflatex
!sudo apt-get install texlive-latex-recommended 
!sudo apt install texlive-latex-extra
!sudo apt install dvipng

In my first attempt, There was an error buried in the install of pdflatex with an incompatible version of folium 0.8.x, so the first command rolls it back to the compatible version from the error trace. Probably not totally necessary to roll back folium, but I haven't tested.

The latex install commands were shamelessly lifted from this answer for latex-equations-do-not-render-in-google-colaboratory-when-using-matplotlib, where they offer a bit more explanation. The whole install process produced quite a bit of output and took some time.

After completed, I was able to generate a pdf file from my LaTex string similar to the example from the package docs:

import pdflatex as ptex

pdfl = ptex.PDFLaTeX.from_texfile(r'/content/my_tex_string_file.tex')
pdf, log, completed_process = pdfl.create_pdf()
with open('testPDF.pdf', 'wb') as pdfout:
        pdfout.write(pdf)

my_tex_string_file.tex was generated from pandas in my test case, and I added a preamble manually (string concatenation) to include the correct latex packages for my desired output, but a quick look through the github page for lcapy shows the same approach may work for lcapy as well.

0

I ran into the same issue myself and after verifying pdflatex is installed with !pdflatex -help, I looked into Lcapy's code. The easiest workaround I found is to comment out line 73 of system.py. I only need schematic tools, so this solution is adequate for me. If you need a proper solution, all the relevant functions are in the same file and it seems that import pdflatex is unnecessary as the library searches for the binary.