gpt4 book ai didi

Python - CalledProcessError : Command '[...]' returned non-zero exit status 127

转载 作者:行者123 更新时间:2023-12-03 21:22:34 31 4
gpt4 key购买 nike

我正在使用 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

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

任何帮助将非常感激

最佳答案

问题在于您的外部脚本“runtex”,而不是您的 Python 代码。它正在返回状态 127;非零状态通常表示错误,并且您已要求子进程在非零状态下抛出异常(通过使用 check_call ),因此它做到了。

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

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

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

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

    关于Python - CalledProcessError : Command '[...]' returned non-zero exit status 127,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52174019/

    31 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com