本文介绍了PyLaTeX:pylatex.errors.CompilerError:未找到LaTex编译器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从此处运行确切的代码a>获取pylatex工作示例.

I am trying to run the exact code from here to get an example of pylatex working.

在我正在使用的目录中,我已经从链接复制并粘贴:

In the directory that I am working in, I have copied and pasted from the link:

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

我总是收到错误消息:

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控制台,然后键入:

You can see some of the things I've tried based on other people's suggestions:1. if I just open a python console in this directory, and type:

from pylatex import Document, Section, Subsection, Command
from pylatex.utils import italic, NoEscape
import pdflatex

没有错误,表示导入成功.

there are no errors, implying importing was successful.

  1. 我看到另一个必须安装perl的建议,它是:

  1. I saw another recommendation that perl must be installed, which it is:

localhost:test1 $ perl --version:返回有关perl的信息

localhost:test1$ perl --version : returns info about perl

我已经按照StackOverflow其他地方的建议指定了编译器:'doc.generate_pdf(clean_tex = False,compiler ='pdflatex')'

I've specified the compiler as was suggested elsewhere on StackOverflow: 'doc.generate_pdf(clean_tex=False,compiler='pdflatex')'

我还能做什么?最终目的是我已经用python生成了字符串和图像,并且我希望将它们都以PDF和格式保存,以防万一有人可以提出更好的选择.P.s.我知道tex堆栈交换,但是我特别需要一种方法来使乳胶与python交互,这就是为什么我在这里询问.

What else can I do? The ultimate aim is I have generated strings and an image with python, and I want to put them both into a PDF and format, in case there is a better alternative that anyone can suggest. P.s. I'm aware of the tex stack exchange, but I specifically need a way for latex to interact with python, which is why I asked here.

推荐答案

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

Apparantly you'll need to run these two apt-get dependencies

sudo apt-get install latexmk
sudo apt-get install -y texlive-latex-extra

还要通过pip安装 pdflatex

pip install pdflatex

然后使用

doc.generate_pdf(compiler ='pdflatex')

这篇关于PyLaTeX:pylatex.errors.CompilerError:未找到LaTex编译器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!