【问题标题】:pdflatex is not installed in google colabpdflatex 未安装在 google colab 中
【发布时间】:2021-07-07 12:05:14
【问题描述】:

我正在尝试使用lcapy's python 库在 google colab 中绘制一些电路。不幸的是,我总是遇到错误:

RuntimeError: pdflatex is not installed

虽然我做了pip install pdflatex 我在 lcapy 的文档中找不到与此错误相关的任何内容。

笔记本可以找到here

【问题讨论】:

  • 我认为你笔记本的某些权限是错误的,我无法打开它。无论如何,您确定 pdflatex 已正确安装吗?你做了pip install pdflatex吗?它似乎在我的 Colab 中正确安装
  • 更新了链接。是的,我做了pip install pdflatex。看起来 colab 无法识别此库。

标签: google-colaboratory pdflatex


【解决方案1】:

我最近在 google colab 中尝试从 pandas 生成的乳胶输出渲染 PDF 时遇到了类似的问题/错误。我收到的错误是抱怨一个文件 (Error Code 2),将“pdflatex”列为丢失的文件,但我确认安装已按照您的报告完成。这使我意识到缺少导致错误的 LaTex 依赖项;回溯对我来说似乎有点误导。这是对我有用的解决方案:

首先,在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

在我的第一次尝试中,pdflatex 的安装中隐藏了一个错误,folium 0.8.x 的版本不兼容,因此第一个命令将其从错误跟踪中回滚到兼容版本。回滚 folium 可能不是完全必要的,但我还没有测试过。

latex 安装命令无耻地从 this answer for latex-equations-do-not-render-in-google-colaboratory-when-using-matplotlib 中提取出来,在那里它们提供了更多解释。整个安装过程产生了相当多的输出并花费了一些时间。

完成后,我能够从我的 LaTex 字符串生成一个类似于 example from the package docs 的 pdf 文件:

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 是在我的测试用例中从 pandas 生成的,我手动添加了一个序言(字符串连接)以包含我想要的输出的正确乳胶包,但快速浏览lcapy 的 github 页面显示同样的方法也可能适用于 lcapy。

【讨论】:

    【解决方案2】:

    我自己也遇到了同样的问题,在验证了使用!pdflatex -help 安装了 pdflatex 之后,我查看了 Lcapy 的代码。我发现的最简单的解决方法是注释掉 system.py 的第 73 行。我只需要原理图工具,所以这个解决方案对我来说已经足够了。如果您需要适当的解决方案,所有相关函数都在同一个文件中,并且在库搜索二进制文件时,import pdflatex 似乎是不必要的。

    【讨论】:

      猜你喜欢
      • 2020-02-20
      • 2020-11-18
      • 1970-01-01
      • 2021-12-20
      • 1970-01-01
      • 2018-07-03
      • 1970-01-01
      • 1970-01-01
      • 2019-06-04
      相关资源
      最近更新 更多