matplotlib.animation错误 - 系统找不到指定的文件

时间:2012-02-09 15:19:11

标签: python animation matplotlib

当尝试在python中运行一个简单的animation example code时,我收到一个我无法解决的错误。

Traceback (most recent call last):
File "D:/CG/dynamic_image2.py", line 29, in <module>
    ani.save('dynamic_images.mp4')
File "C:\Python27\lib\site-packages\matplotlib\animation.py", line 127, in save
    self._make_movie(filename, fps, codec, frame_prefix)
File "C:\Python27\lib\site-packages\matplotlib\animation.py", line 164, in _make_movie
    stdout=PIPE, stderr=PIPE)
File "C:\Python27\lib\subprocess.py", line 679, in __init__
    errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 893, in _execute_child
    startupinfo)
WindowsError: [Error 2] The system cannot find the file specified

我发现了类似的情况(link1link2),但我仍然不知道如何解决我的问题......

我正在使用: Python 2.7.2 | EPD 7.2-2(32位)| (默认,2011年9月14日,11:02:05)[win v300 32位(英特尔)]在win32上

我希望有人可以帮助我!

1 个答案:

答案 0 :(得分:1)

我有同样的情况,但如果你只是想看动画那么解决方案很简单。您的proglem与ani.save('dynamic_images.mp4')相关,动画本身不需要它。只是评论出来。您的代码由于缺少已安装的编解码器而崩溃(最有可能)。 animation.py包含以下代码。如果_make_movie的参数编解码器为None,则使用ffmpeg(google it),然后您需要安装此路径并在路径中使用。否则你可以使用mencoder,它也需要安装在路径中。

def ffmpeg_cmd(self, fname, fps, codec, frame_prefix):
    # Returns the command line parameters for subprocess to use
    # ffmpeg to create a movie
    return ['ffmpeg', '-y', '-r', str(fps), '-b', '1800k', '-i',
        '%s%%04d.png' % frame_prefix, fname]

def mencoder_cmd(self, fname, fps, codec, frame_prefix):
    # Returns the command line parameters for subprocess to use
    # mencoder to create a movie
    return ['mencoder', 'mf://%s*.png' % frame_prefix, '-mf',
        'type=png:fps=%d' % fps, '-ovc', 'lavc', '-lavcopts',
        'vcodec=%s' % codec, '-oac', 'copy', '-o', fname]

def _make_movie(self, fname, fps, codec, frame_prefix, cmd_gen=None):
    # Uses subprocess to call the program for assembling frames into a
    # movie file.  *cmd_gen* is a callable that generates the sequence
    # of command line arguments from a few configuration options.
    from subprocess import Popen, PIPE
    if cmd_gen is None:
        cmd_gen = self.ffmpeg_cmd
    command = cmd_gen(fname, fps, codec, frame_prefix)
    verbose.report('Animation._make_movie running command: %s'%' '.join(command))
    proc = Popen(command, shell=False,
        stdout=PIPE, stderr=PIPE)
    proc.wait()
相关问题