Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am working on a microservice using Bottle in Python, where I need to generate a PDF using a .tex file. I am using subprocess to generate the PDF but I keep getting the same error over and over again:

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

I already tried all the solutions I found for the same error in Stackverflow, however none seem to solve my problem. My code is as follows

@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')

And this is my runtex file

echo $1
cd tmp
pdflatex $1

Any help would be much appreciated

like image 256
Juan David Ospina Avatar asked Sep 04 '18 21:09

Juan David Ospina


1 Answers

The problem is in your external script 'runtex', not in your Python code. It is returning status 127; a nonzero status usually indicates an error, and you have asked subprocess to throw an exception on nonzero status (by using check_call), so it did.

127 generally indicates "command not found", so that is probably the case here (although a program could return 127 for its own reasons).

If that's all that's in runtex, you should probably:

  • Add a shebang line: #!/bin/sh as the first line
  • Make sure it has execute permission (chmod +x runtex)

The exit status of a script is the exit status of the last command, so it seems likely that pdflatex isn't being found in the path. Make sure it's installed and on $PATH in your program's environment!

like image 60
Nick Matteo Avatar answered Sep 29 '22 17:09

Nick Matteo