python - 生成 PDF 文件时出现 Pylatex 错误 - 没有这样的文件或目录

标签 python nosuchfileexception

我只想使用 Pylatex 生成 pdf 文件。我查看了基本示例并重新运行脚本,但它引发了错误:OSError:[Errno 2]没有这样的文件或目录。

这是我的脚本:

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


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__':
    reload(sys)
    sys.setdefaultencoding('utf8')
    # Basic document
    doc = Document()
    fill_document(doc)

    doc.generate_pdf("full")
    doc.generate_tex()

错误:

Traceback (most recent call last):
  File "/Users/code/Test Generator/Generate.py", line 34, in <module>
    doc.generate_pdf("full")
  File "/Library/Python/2.7/site-packages/pylatex/document.py", line 227, in generate_pdf
    raise(os_error)
OSError: [Errno 2] No such file or directory

有人可以帮助我吗? :-D 非常感谢。

最佳答案

根据错误周围的代码,您可能缺少 latex 编译器:

compilers = (
    ('latexmk', latexmk_args),
    ('pdflatex', [])
)

尝试这样做:

apt-get install latexmk

关于python - 生成 PDF 文件时出现 Pylatex 错误 - 没有这样的文件或目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40039763/

相关文章:

python - Airflow :导入错误:没有名为 configparser 的模块

java - 使用 java.nio.file.Files.createTempDirectory 时出现 NoSuchFileException

java - .jar 中出现 NoSuchFileException,但 Eclipse 中没有

java - 从 R 运行 jar 时 rJava NoSuchFileException

python - 如何删除(或取消网格)存储在列表中的 Tkinter GUI 对象 (Python)

python - 如何设计避免暴露内部结构的库公共(public) api?

python - 列表数据消失

python - 使用python从sql中提取数据,进行转换并写回sql表