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

car*_*rla 5 python animation matplotlib

当试图在python中运行一个简单的动画示例代码时,我收到一个我无法解决的错误.

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
Run Code Online (Sandbox Code Playgroud)

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

我正在使用:Python 2.7.2 | EPD 7.2-2(32位)| (默认情况下,2011年9月14日,11:02:05)[winv上的MSC v.1500 32位(英特尔)]

我希望有人可以帮助我!

小智 3

我也遇到了同样的情况,但是如果你只想看动画,解决方案很简单。您的程序与 ani.save('dynamic_images.mp4') 相关,动画本身不需要它。注释掉就可以了 由于缺少安装的编解码器(很可能),您的代码崩溃了。Animation.py 包含以下代码。如果 _make_movie 的参数编解码器为 None,使用 ffmpeg(google 一下),那么您需要安装此编解码器并在您的路径中可用。否则,您可以使用 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()
Run Code Online (Sandbox Code Playgroud)