如何在CGI中使用`latex` Python模块?

时间:2019-02-17 08:17:47

标签: python apache latex cgi pdflatex

我有一个Apache服务器(在Arch Linux上通过XAMPP运行),该服务器具有一个CGI,应将LaTeX转换为PDF。

CGI文件中的代码为:

#! /usr/bin/python
import cgi
import sys
from latex import *
print("Content-Type: text/html\n")
sys.stderr = sys.stdout

min_latex = (r"\documentclass{article}"
             r"\begin{document}"
             r"Hello, world!"
             r"\end{document}")

from latex import build_pdf

pdf = build_pdf(min_latex)

print(bytes(pdf)[:10])

当我在浏览器中调用CGI时,我对此表示欢迎:

Traceback (most recent call last):
  File "/usr/lib/python3.7/site-packages/latex/build.py", line 111, in build_pdf
    stderr=open(os.devnull, 'w'), )
  File "/usr/lib/python3.7/subprocess.py", line 341, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['latexmk', '-pdf', '-pdflatex=pdflatex -interaction=batchmode -halt-on-error -no-shell-escape -file-line-error %O %S', '/tmp/tmp6xrmuvgr/tmptrv6zwoh.latex']' returned non-zero exit status 12.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/opt/lampp/htdocs/pdftest.py", line 15, in <module>
    pdf = build_pdf(min_latex)
  File "/usr/lib/python3.7/site-packages/latex/build.py", line 232, in build_pdf
    return builder.build_pdf(source, texinputs)
  File "<decorator-gen-1>", line 2, in build_pdf
  File "/usr/lib/python3.7/site-packages/data/decorators.py", line 82, in _
    return f(*bvals.args, **bvals.kwargs)
  File "/usr/lib/python3.7/site-packages/latex/build.py", line 113, in build_pdf
    raise_from(LatexBuildError(base_fn + '.log'), e)
  File "/usr/lib/python3.7/site-packages/future/utils/__init__.py", line 400, in raise_from
    exec(execstr, myglobals, mylocals)
  File "<string>", line 1, in <module>
latex.exc.LatexBuildError: None

使用标准Python解释器调用时,程序可以正确运行。为什么在CGI中运行此代码失败?我怎样才能解决这个问题?

0 个答案:

没有答案