【问题标题】:Python - CalledProcessError: Command '[...]' returned non-zero exit status 127Python - CalledProcessError:命令'[...]'返回非零退出状态127
【发布时间】:2019-02-09 22:38:25
【问题描述】:

我正在使用 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 脚本是否有效?如果是,你能告诉我们完整的命令吗?
  • 是的,没有意识到我正在使用的计算机没有安装 LaTeX 发行版,因此 pdflatex 命令不起作用。我的错,谢谢你现在这将解决我的问题!

标签: python python-2.7 bottle


【解决方案1】:

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

bash: pdflatex: command not found

安装了 MacTeX,现在一切正常!

【讨论】:

    【解决方案2】:

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

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

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-11
      • 1970-01-01
      • 1970-01-01
      • 2019-10-02
      • 1970-01-01
      • 2019-08-12
      • 2019-11-28
      • 2021-02-15
      相关资源
      最近更新 更多