2👍
The error you’re getting means that the subprocess
module cannot find the executable it wants to run.
If the script runs from the command-line then the gs
executable clearly exists, so it looks like the gs
executable is not on the PATH
that your Django application is running with. Does it help if you specify the full path to gs
(e.g. /usr/bin/gs
) instead?
Incidentally, I get the same error message if I try to get subprocess
to start a nonexistent executable:
Python 2.7.3 (default, Aug 1 2012, 05:14:39)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
>>> subprocess.call("nonexistent")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/subprocess.py", line 493, in call
return Popen(*popenargs, **kwargs).wait()
File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1249, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
EDIT: if your process uses command-line arguments, the executable name and the argument must be specified as separate list items, as in the second of your attempts at running gs
:
Python 2.7.3 (default, Aug 1 2012, 05:14:39)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
>>> subprocess.call("ls /usr")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/subprocess.py", line 493, in call
return Popen(*popenargs, **kwargs).wait()
File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1249, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
>>> subprocess.call(["ls", "/usr"])
bin games include lib lib32 lib64 local sbin share src X11R6
0
The first example didn’t work because I don’t have an executable named ls /usr
anywhere on my system.
Could you try modifying the second of your attempts to use the full path of gs
, for example:
sp = subprocess.Popen(['/usr/bin/gs', '-dSAFER', '-dNOPAUSE', '-dQUIET', '-dBATCH', '-sDEVICE=jpeg', '-sOUTPUTFILE=' + path + "/static.jpg", path + "/source.pdf"])