报错信息:
OSError: MoviePy Error: creation of None failed because of the following error:
[WinError 2] 系统找不到指定的文件。.
.This error can be due to the fact that ImageMagick is not installed on your computer, or (for Windows users) that you didn't specify the path to the ImageMagick binary in file conf.py, or that the path you specified is incorrect
根据报错信息定位到moviepy/video/VideoClip.py中这一段代码:
try:
subprocess_call(cmd, logger=None)
except (IOError, OSError) as err:
error = ("MoviePy Error: creation of %s failed because of the "
"following error:\n\n%s.\n\n." % (filename, str(err))
+ ("This error can be due to the fact that ImageMagick "
"is not installed on your computer, or (for Windows "
"users) that you didn't specify the path to the "
"ImageMagick binary in file conf.py, or that the path "
"you specified is incorrect"))
raise IOError(error)
在subprocess_call前面加一句print(cmd)再次运行,发现cmd中调用的是ImageMagick安装路径下的convert.exe这个运行程序,但我在安装路径只能找到magick.exe,并没有convert.exe
是不是换成magick.exe就行了呢?
试试看吧!error信息中有提到conf.py,于是试着打开moviepy/config.py,找到了这一段代码
if IMAGEMAGICK_BINARY=='auto-detect':
if os.name == 'nt':
try:
key = wr.OpenKey(wr.HKEY_LOCAL_MACHINE, 'SOFTWARE\\ImageMagick\\Current')
IMAGEMAGICK_BINARY = wr.QueryValueEx(key, 'BinPath')[0] + r"\convert.exe"
key.Close()
except:
IMAGEMAGICK_BINARY = 'unset'
elif try_cmd(['convert'])[0]:
IMAGEMAGICK_BINARY = 'convert'
else:
IMAGEMAGICK_BINARY = 'unset'
将convert.exe改成magick.exe后再次运行代码,成功运行!
看来是新版本的ImageMagick做了变动,老版moviepy才会出错,这样看来直接更新moviepy或许就能解决问题,或者也可以通过moviepy提供的方法来改设置:
import moviepy.config as config
config.change_settings({"IMAGEMAGICK_BINARY": r"C:\Program Files\ImageMagick-<version>\magick.exe"})