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

问题描述 投票:1回答:2

我正在使用Python中的Bottle进行微服务,我需要使用.tex文件生成PDF。我正在使用子进程生成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

我已经尝试了在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')

这是我的runtex文件

echo $1
cd tmp
pdflatex $1

任何帮助将非常感激

python python-2.7 bottle
2个回答
0
投票

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

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

如果这就是runtex的全部内容,你应该:

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

脚本的退出状态是最后一个命令的退出状态,因此很可能在路径中找不到pdflatex。确保它已安装在程序环境中的$PATH上!


0
投票

我在工作的计算机上没有LaTeX发行版。它返回错误127,因为runtex中的pdflatex命令无法正常工作。即

bash: pdflatex: command not found

安装了MacTeX,现在一切都像魅力一样!

© www.soinside.com 2019 - 2024. All rights reserved.