Search code examples
pythonpython-2.7bottle

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


Solution

  • I had no LaTeX distribution in the computer I was working on. It was returning error 127 because the pdflatex command in runtex was not working. i.e

    bash: pdflatex: command not found
    

    Installed MacTeX and now everything is working like a charm!