【发布时间】:2019-04-09 21:56:11
【问题描述】:
我正在尝试运行来自 here 的确切代码,以获取 pylatex 工作的示例。
在我正在工作的目录中,我从链接中复制并粘贴了:
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
没有错误,说明导入成功。
-
我看到另一个建议必须安装perl,它是:
localhost:test1$ perl --version : 返回有关 perl 的信息
我已经按照 StackOverflow 上其他地方的建议指定了编译器:'doc.generate_pdf(clean_tex=False,compiler='pdflatex')'
我还能做什么?最终目标是我用 python 生成了字符串和图像,我想把它们都变成 PDF 和格式,以防任何人都可以提出更好的选择。附:我知道 tex 堆栈交换,但我特别需要一种让乳胶与 python 交互的方法,这就是我在这里问的原因。
【问题讨论】:
-
您找到解决此问题的方法了吗?我也面临同样的问题
-
很遗憾,我没有找到,但我很想找到一个!