Skip to content

Getting Lcapy working on Google Colab with pdflatex and circuitikz #168

@costajr2019

Description

@costajr2019

Hi everyone,

I ran into a couple of issues while trying to use Lcapy on Google Colab to draw circuits and generate schematics.

The first problem happened when installing LaTeX packages:

!sudo apt-get install texlive-latex-recommended --quiet

I got several 404 Not Found errors for packages such as:

libkpathsea6
libptexenc1
libsynctex2
libtexlua53
libtexluajit2
texlive-binaries

It turned out that Colab was using an outdated package index, so cleaning and updating apt before installation fixed that part.

Then, when trying to draw a circuit in Lcapy, I got:

RuntimeError: circuitikz is not installed

Even after installing LaTeX-related packages, the error continued. In my case, the cause was twofold:

the TeX installation was still incomplete for circuitikz

I had accidentally created a local empty file called circuitikz.sty after a failed wget command, and LaTeX was finding that empty local file first

This sequence worked for me in Google Colab:

!rm -f circuitikz.sty circuitikzgit.sty teste_circuitikz.tex teste_circuitikz.log teste_circuitikz.aux

!sudo apt-get clean
!sudo rm -rf /var/lib/apt/lists/*
!sudo apt-get update -qq
!sudo apt-get install -y texlive texlive-pictures texlive-latex-extra dvipng

!pip install -q --upgrade lcapy

After that, Lcapy was able to draw circuits normally.

For example:
from lcapy import Circuit

a = Circuit("""
V 1 0 step 6; down=1.5
R 1 2 2; right=1.5
C 2 0_2 4; down
W 0 0_2; right
""")

a.draw()

So the key points were:

  • clean the apt cache and package lists
  • run apt-get update
  • install a sufficiently complete TeX Live set
  • remove any invalid local circuitikz.sty file
  • verify installation with:
    !kpsewhich circuitikz.sty

I hope this helps anyone trying to run Lcapy in Colab.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions