尽管文件存在,但找不到它们

时间:2014-02-16 15:37:12

标签: python subprocess python-imaging-library

我有这个Python代码:

from PIL import Image
from PIL import ImageFont
from PIL import ImageDraw
import subprocess
import shlex

font = ImageFont.truetype("/usr/share/fonts/truetype/ubuntu-font-family/Ubuntu-C.ttf", 66)
text = "me@example.com"
size = font.getsize(text)

img = Image.new('RGBA', size=size, color=(0, 0, 0, 0))
draw = ImageDraw.Draw(img)
draw.text((0, 0), text, fill=(209, 239, 8), font=font)

img.save('/home/alex/label.jpg')

cmd = 'composite -dissolve 25% -gravity south /home/alex/label.jpg /home/alex/in.jpg /home/alex/out1.jpg'
proc = subprocess.Popen(shlex.split(cmd))
proc.communicate()

label.jpgin.jpg存在,out1.jpg,显然,不是。但我总是得到错误:

    proc = subprocess.Popen(shlex.split(cmd))
  File "/usr/lib/python2.7/subprocess.py", line 711, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1308, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

这是怎么回事?

1 个答案:

答案 0 :(得分:1)

我认为您的问题是PATH,请尝试指定复合的完整路径