2012-02-09 95 views
5

当试图在python中运行简单的animation example code时,出现一个我无法解决的错误。matplotlib.animation错误 - 系统找不到指定的文件

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)[win32上的[MSC v.1500 32位(Intel)]]

我希望有人能帮助我!

+0

我发现我可以运行代码并获得动画,如果我从** C更改行163:\ Python27 \ LIB \站点包\ matplotlib \ animation.py **从'proc等于POPEN (命令,shell = False,stdout = PIPE,stderr = PIPE)'到'proc = Popen(命令,shell = True,stdout = PIPE,stderr = PIPE)'。 – carla 2012-02-10 14:37:15

+0

但是,我不确定** animation.py **文件中的这种更改是否“安全”... [更多信息](http://docs.python.org/library/subprocess.html#frequently -used-arguments) – carla 2012-02-10 14:48:13

回答

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() 
+0

你说得对。事实上,我已经ffmpeg安装,但它不是在我的Python路径... 这个[stackoverflow question](http://stackoverflow.com/questions/9256829/how-can-i-save-animation-artist-animation/9281433#9281433)已经给我提示了! 感谢您的帮助! – carla 2012-03-07 10:31:41

相关问题