Python - CalledProcessError:命令“[...]”返回非零退出状态 127

Jua*_*ina 7 python bottle python-2.7

我正在使用 Python 中的 Bottle 开发微服务,我需要使用 .tex 文件生成 PDF。我正在使用 subprocess 生成 PDF,但我一遍又一遍地收到相同的错误:

Traceback (most recent call last):
File "/Users/casa/Desktop/tesisform/bottle.py", line 763, in _handle
return route.call(**args)
File "/Users/casa/Desktop/tesisform/bottle.py", line 1577, in wrapper
rv = callback(*a, **ka)
File "tesis.py", line 114, in tesis_form
subprocess.check_call(["./runtex", texfname])
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 540, in check_call
raise CalledProcessError(retcode, cmd)
CalledProcessError: Command '['./runtex', u'111111']' returned non-zero exit status 127
Run Code Online (Sandbox Code Playgroud)

我已经尝试了在 Stackverflow 中针对相同错误找到的所有解决方案,但是似乎没有一个解决方案可以解决我的问题。我的代码如下

@route('/pdf')
def tesis_form():
    actn = request.query.actn
    fname = "actas/"+actn + ".json"
    with open(fname,"r") as f:
        data = json.load(f)
    tex = template('tesis-evaluation-tex', data)
    tex = tex.encode('utf-8')
    texfname = "%s" % (actn)
    with open("tmp/"+actn+".tex","w") as f:
        f.write(tex)
    subprocess.check_call(["./runtex", texfname])
    return static_file(actn+".pdf", root='tmp')
Run Code Online (Sandbox Code Playgroud)

这是我的 runtex 文件

echo $1
cd tmp
pdflatex $1
Run Code Online (Sandbox Code Playgroud)

任何帮助将非常感激

Nic*_*teo 7

问题出在您的外部脚本“runtex”中,而不是在您的 Python 代码中。它返回状态 127;非零状态通常表示错误,并且您已要求子进程在非零状态上抛出异常(通过使用check_call),所以它确实发生了。

127 通常表示“未找到命令”,因此这里可能就是这种情况(尽管程序可能由于其自身原因返回 127)。

如果这就是 中的全部内容runtex,您可能应该:

  • 添加 shebang 行:#!/bin/sh作为第一行
  • 确保它具有执行权限(chmod +x runtex

脚本的退出状态是最后一个命令的退出状态,因此似乎pdflatex在路径中找不到该退出状态。确保它已安装并$PATH在您的程序环境中开启!


Jua*_*ina 3

我正在使用的计算机上没有 LaTeX 发行版。它返回错误 127,因为 runtex 中的 pdflatex 命令不起作用。IE

bash: pdflatex: command not found
Run Code Online (Sandbox Code Playgroud)

安装了 MacTeX,现在一切都运行得非常顺利!