【问题标题】:Pylatex error when generate PDF file - No such file or directory生成 PDF 文件时出现 Pylatex 错误 - 没有这样的文件或目录
【发布时间】:2017-02-23 16:26:39
【问题描述】:

我只想使用 Pylatex 生成 pdf 文件。我查看了基本示例并重新运行脚本,但它引发了错误:OSError: [Errno 2] No such file or directory。

这是我的脚本:

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 非常感谢。

【问题讨论】:

  • 我遇到了同样的问题。你找到解决办法了吗?

标签: python nosuchfileexception


【解决方案1】:

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

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

尝试这样做:

apt-get install latexmk

【讨论】:

    【解决方案2】:

    运行 python 脚本时,您的 PATH 中是否有 pdflatex 命令?并 确定您已经安装了 texlive,如果仍然无法正常工作,请尝试安装 latexmk。

    我遇到了同样的问题,只要设置你的 PATH,考虑到你已经安装了 texlive。

    就我而言,他的问题是 PATH。我正在使用 Flask 运行一个网站,使用 uWsgi 作为服务进行托管,并且 PATH 是在我的 virtualenv 中设置的。

    所以我修复了添加“:/usr/bin”并工作,见下文:

    [Unit]
    Description=uWSGI instance to serve myproject
    After=network.target
    
    [Service]
    User=www-data
    Group=www-data
    WorkingDirectory=/sites/simapp
    Environment="PATH=/env/flask3/bin:/usr/bin"
    ExecStart=/env/flask3/bin/uwsgi --ini /sites/simapp/simapp.ini
    
    [Install]
    WantedBy=multi-user.target
    

    【讨论】:

      猜你喜欢
      • 2021-10-25
      • 1970-01-01
      • 1970-01-01
      • 2010-12-18
      • 1970-01-01
      • 1970-01-01
      • 2021-10-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多