我有以下代码:
import subprocess
convertargs = ['convert', 'image1.tif', 'img2.tif', 'pdf:-']
print "Content-type: application/pdf\r\n\r\n"
pdf = subprocess.Popen(convertargs, stdout=subprocess.PIPE)
pdf, error = pdf.communicate()
print pdf它应该采取转换,使用imagemagick的转换,将图像转换成一个pdf。
我知道这是因为当我在shell上运行以下代码时:
./pdf.py > test.pdf它为我创建了一个整洁的PDF和正确的图像。但是,当我访问www.myhost.com/pdf.py时,它不起作用。我也搞不懂为什么。下面是我的apache错误日志中的内容:
Traceback (most recent call last):: /Library/WebServer/Documents/pdf.py
File "/Library/WebServer/Documents/pdf.py", line 59, in <module>: /Library/WebServer/Documents/pdf.py
pdf = subprocess.Popen(convertargs, stdout=subprocess.PIPE): /Library/WebServer/Documents/pdf.py
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 710, in __init__: /Library/WebServer/Documents/pdf.py
errread, errwrite): /Library/WebServer/Documents/pdf.py
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1335, in _execute_child: /Library/WebServer/Documents/pdf.py
raise child_exception: /Library/WebServer/Documents/pdf.py
OSError: [Errno 2] No such file or directory: /Library/WebServer/Documents/pdf.py发布于 2016-04-03 20:34:21
subprocess.Popen找不到convert,可能是因为the服务器使用的是不同的$PATH。尝试将其提供给convert的完整路径,而不仅仅是convert。
https://stackoverflow.com/questions/36390616
复制相似问题