我正在使用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
任何帮助将非常感激
问题出在你的外部脚本'runtex'中,而不是你的Python代码中。它返回状态127;非零状态通常表示错误,并且您已经要求子进程在非零状态上抛出异常(通过使用check_call
),所以它确实如此。
127通常表示“未找到命令”,因此这可能就是这种情况(尽管程序可能因其自身原因返回127)。
如果这就是runtex
的全部内容,你应该:
#!/bin/sh
作为第一行chmod +x runtex
)脚本的退出状态是最后一个命令的退出状态,因此很可能在路径中找不到pdflatex
。确保它已安装在程序环境中的$PATH
上!
我在工作的计算机上没有LaTeX发行版。它返回错误127,因为runtex中的pdflatex命令无法正常工作。即
bash: pdflatex: command not found
安装了MacTeX,现在一切都像魅力一样!