Python、Imagemagick 和子进程调用

Python, Imagemagick, and subprocess call

尝试在 python 脚本中使用子进程调用 运行 Imagemagick 命令。 我在 /usr/local/Cellar 中安装了 imagemagick,所以我尝试了两个选项,因为它看起来好像找不到转换命令。

顺便说一下,'convert' 命令是一个 imagemagick 命令。 :) 这是我的代码中与它直接相关的部分。

import sys, os, subprocess, string
tempo = 8; #this is just for sample purposes, in the actual code this variable is imported from a csv file

# test with just captioning one image and not whole loop
subprocess.call('convert rgb10.png -pointsize 50 -draw "text 180,180 ' + str(tempo) + '" rgb10-n.png')

我也试过 "subprocess.call('/usr/local/Cellar/imagemagick/6.8.9-8/bin/c...." 因为我认为它可能找不到命令。

此外,我 当我 运行 在我的终端命令行(而不是脚本)中执行此命令时,它有效 (ex: convert rgb298.png -pointsize 50 -draw "text 180,180 'test' " rgb298-n.png) 所以我知道一定是我的子进程调用有问题。

这是 我在 运行 时收到的 错误:

   subprocess.call('/usr/local/Cellar/imagemagick/6.8.9-8/bin/convert rgb10.png -pointsize 50 -draw "text 180,180 ' + str(tempo[9]) + '" rgb10-n.png')
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subprocess.py", line 470, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subprocess.py", line 623, in __init__
    errread, errwrite)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subprocess.py", line 1141, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

注意:我也试过 subprocess.call('python2.6 convert rgb10.png ...

...我已经开始工作了,这太傻了!

已添加,shell=True

subprocess.call('convert rgb10.png -pointsize 50 -draw "text 180,180 ' + str(tempo) + '" rgb10-n.png', shell=True)

它现在对其他 运行 解决这个问题的人有效。

除了它实际上没有绘制或考虑变量 'tempo',也就是不处理 + str(tempo) + bit