我正试图从这里运行确切的代码,以获得幽门工作的一个例子。
在我正在工作的目录中,我从链接中复制和粘贴了:
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控制台,然后键入:
from pylatex import Document, Section, Subsection, Command
from pylatex.utils import italic, NoEscape
import pdflatex没有错误,暗示导入是成功的。
我还能做什么?最终的目标是我已经用python生成了字符串和图像,我想把它们都转换成PDF和格式,以防有更好的选择,任何人都可以建议。附注:我知道tex堆栈交换,但我特别需要一种与python交互的方法,这就是我在这里问的原因。
发布于 2020-07-22 15:54:13
显然,您需要运行这两个apt-get依赖项
sudo apt-get install latexmk
sudo apt-get install -y texlive-latex-extra还可以用pip安装pdflatex
pip install pdflatex
然后使用
doc.generate_pdf(compiler='pdflatex')
发布于 2021-03-24 13:27:01
我也犯了同样的错误,我的问题是我忘了在Windows环境路径中添加pdflatex (通过MiKTex)。我的代码在重新加载我的终端后工作。顺便说一下,我还没有安装Perl。
https://stackoverflow.com/questions/55601901
复制相似问题