首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PyLaTeX: pylatex.errors.CompilerError:没有找到LaTex编译器

PyLaTeX: pylatex.errors.CompilerError:没有找到LaTex编译器
EN

Stack Overflow用户
提问于 2019-04-09 21:56:11
回答 2查看 4.4K关注 0票数 9

我正试图从这里运行确切的代码,以获得幽门工作的一个例子。

在我正在工作的目录中,我从链接中复制和粘贴了:

代码语言:javascript
复制
from pylatex import Document, Section, Subsection, Command
from pylatex.utils import italic, NoEscape
import pdflatex


def fill_document(doc):
    """Add a section, a subsection and some text to the document.

    :param doc: the document
    :type doc: :class:`pylatex.document.Document` instance
    """
    with doc.create(Section('A section')):
        doc.append('Some regular text and some ')
        doc.append(italic('italic text. '))

        with doc.create(Subsection('A subsection')):
            doc.append('Also some crazy characters: $&#{}')


if __name__ == '__main__':
    # Basic document
    doc = Document('basic')
    fill_document(doc)

    doc.generate_pdf(clean_tex=False,compiler='pdflatex')
    doc.generate_tex()

    # Document with `\maketitle` command activated
    doc = Document()

    doc.preamble.append(Command('title', 'Awesome Title'))
    doc.preamble.append(Command('author', 'Anonymous author'))
    doc.preamble.append(Command('date', NoEscape(r'\today')))
    doc.append(NoEscape(r'\maketitle'))

    fill_document(doc)

    doc.generate_pdf('basic_maketitle', clean_tex=False)

    # Add stuff to the document
    with doc.create(Section('A second section')):
        doc.append('Some text.')

    doc.generate_pdf('basic_maketitle2', clean_tex=False)
    tex = doc.dumps()  # The document as string in LaTeX syntax

我一直知道这个错误:

代码语言:javascript
复制
Traceback (most recent call last):
  File "test.py", line 26, in <module>
    doc.generate_pdf(clean_tex=False,compiler='pdflatex')
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.7/site-packages/pylatex/document.py", line 280, in generate_pdf
    'Either specify a LaTex compiler ' +
pylatex.errors.CompilerError: No LaTex compiler was found

根据其他人的建议,您可以看到我尝试过的一些事情: 1.如果我只是在这个目录中打开python控制台,然后键入:

代码语言:javascript
复制
from pylatex import Document, Section, Subsection, Command
from pylatex.utils import italic, NoEscape
import pdflatex

没有错误,暗示导入是成功的。

  1. 我看到了另一条关于必须安装perl的建议,即: localhost:test1 1$ perl --version :返回有关perl的信息
  2. 我已经按照StackOverflow中其他地方的建议指定了编译器:“doc.generate_pdf(clean_tex=False,编译器=‘pdflatex’)”

我还能做什么?最终的目标是我已经用python生成了字符串和图像,我想把它们都转换成PDF和格式,以防有更好的选择,任何人都可以建议。附注:我知道tex堆栈交换,但我特别需要一种与python交互的方法,这就是我在这里问的原因。

EN

回答 2

Stack Overflow用户

发布于 2020-07-22 15:54:13

显然,您需要运行这两个apt-get依赖项

代码语言:javascript
复制
sudo apt-get install latexmk
sudo apt-get install -y texlive-latex-extra

还可以用pip安装pdflatex

pip install pdflatex

然后使用

doc.generate_pdf(compiler='pdflatex')

票数 5
EN

Stack Overflow用户

发布于 2021-03-24 13:27:01

我也犯了同样的错误,我的问题是我忘了在Windows环境路径中添加pdflatex (通过MiKTex)。我的代码在重新加载我的终端后工作。顺便说一下,我还没有安装Perl。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55601901

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档