8

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

2
  • Does the runtex script work when you're running it through the command line? If yes, can you show us the full command? Commented Sep 4, 2018 at 21:24
  • Yeah, didn't realize the computer I was working on had no LaTeX distribution installed, hence the pdflatex command was not working. My bad, thank you now this will solve my problem! Commented Sep 4, 2018 at 21:38

2 Answers 2

7

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!

Sign up to request clarification or add additional context in comments.

Comments

3

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!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.