2012-02-09 42 views
5

Khi cố gắng chạy một đơn giản animation example code trong python, tôi gặp lỗi mà tôi không thể giải quyết được.lỗi matplotlib.animation - Hệ thống không thể tìm thấy tệp được chỉ định

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 

tôi thấy tình huống tương tự (link1, link2) nhưng tôi vẫn không biết làm thế nào để giải quyết tôi ...

Tôi đang sử dụng: Python 2.7.2 | EPD 7,2-2 (32 -bit) | (mặc định, ngày 14 tháng 9 năm 2011, 11:02:05) [MSC v.1500 32 bit (Intel)] trên win32

Tôi hy vọng ai đó có thể giúp tôi!

+0

Tôi phát hiện ra mình có thể chạy mã và nhận hoạt ảnh, nếu tôi thay đổi dòng 163 từ ** C: \ Python27 \ Lib \ site-packages \ matplotlib \ animation.py ** từ 'proc = Popen (lệnh, shell = False, stdout = PIPE, stderr = PIPE) 'tới' proc = Popen (lệnh, shell = Đúng, stdout = PIPE, stderr = PIPE) '. – carla

+0

Tuy nhiên, tôi không chắc chắn cách "an toàn" là thay đổi này trong tệp ** animation.py ** ... [thêm thông tin tại đây] (http://docs.python.org/library/subprocess.html#frequently đối số sử dụng) – carla

Trả lời

1

Tôi đã có tình huống tương tự, nhưng việc sollution rất đơn giản nếu bạn chỉ muốn xem hoạt ảnh. Proglem của bạn có liên quan đến ani.save ('dynamic_images.mp4'), không cần thiết cho hoạt ảnh. Chỉ cần bình luận nó ra. Mã của bạn bị treo do thiếu codec được cài đặt (rất có thể). anim.py chứa mã bên dưới. Nếu các đối số codec để _make_movie là Không có, ffmpeg (google nó) được sử dụng, sau đó bạn cần phải có một trong những cài đặt và có sẵn trong đường dẫn của bạn. Nếu không, bạn có thể sử dụng mencoder mà cũng cần phải được cài đặt và trong đường dẫn.

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

Bạn nói đúng. Trong thực tế, tôi đã có ffmpeg instaled nhưng nó không phải là trên con đường trăn của tôi ... [câu hỏi stackoverflow] này (http://stackoverflow.com/questions/9256829/how-can-i-save-animation-artist-animation/9281433 # 9281433) đã cho tôi gợi ý đó! Cảm ơn sự giúp đỡ của bạn! – carla

Các vấn đề liên quan