10

I am relatively new to Python (I used MATLAB a lot more). I essentially want to be able to make and save animations. So I went and checked how it's done and found this : http://jakevdp.github.io/blog/2012/08/18/matplotlib-animation-tutorial/

I straight up copied/pasted the code in an IPython Notebook.

I understand that ffmpeg must be installed, which I thought I did (according to http://www.wikihow.com/Install-FFmpeg-on-Windows). The path is C:/ffmpeg. It does work when I try ffmpeg -version in the command prompt. It also works in WinPython's command prompt. I don't know if it helps, but the path for Ipython is : C:\Users\Sal\WinPython-32bit-3.3.2.3\python-3.3.2\Scripts /

However, it still doesn't work. The error given is : AttributeError: 'str' object has no attribute 'saving' This error occurs at the .save command of course. I even tried to add what's below. Doesn't do anything extra. writer = 'ffmpeg'

I am using Windows 7, WinPython3.3.

Thank you very much

selimb
  • 360
  • 1
  • 4
  • 11
  • 2
    Post the relevant part of the code where your error occurs – SpliFF Nov 22 '13 at 05:42
  • What version of mpl are you using? The animation writer support is (relatively) new. – tacaswell Nov 22 '13 at 16:11
  • @Kreger51 Did you success in saving your animation? I get the same problem!! I don't know why I can't generate an avi file usinf the command `anim.save('mymovie.mp4',writer=mywriter)` and I get an error message instead! thank you –  Mar 23 '14 at 17:18

1 Answers1

20

I came across the exact same error as I started working with animations using the exact same example to start with. First of all,

I am using Windows 7, Python 2.7.6, matplotlib 1.3.1

Short answer: Try to set up the FFMpegWriter yourself by

mywriter = animation.FFMpegWriter()
anim.save('mymovie.mp4',writer=mywriter)

Long answer: I am quite sure that there is a bug in matplotblib.animation.save There is the following line

if is_string_like(writer):

to catch the case that the user defined writer is actually not a writer function but just its name. It then instanciates an instance of that writer if it's available

if writer in writers.avail:
     writer = writers[writer](fps, codec, bitrate,
                              extra_args=extra_args,
                              metadata=metadata

However, and here is the bug, if the user defined writer is not in writers.avail it just uses

writer = writers.list()[0]

which itself returns a string with the name of the writer to be used. However, this string is nowhere used to actually instanciate a writer object!

Sascha
  • 456
  • 4
  • 6
  • 1
    Your short answer worked for me. One minor comment: to be consistent with the [example cited in the original question](http://jakevdp.github.io/blog/2012/08/18/matplotlib-animation-tutorial/), it should be `animation.FFMpegWriter()` instead of `animator.FFMpegWriter()` – jorgeh Dec 20 '13 at 01:58
  • @Sascha Could you please specify which method is correct? I tried the short one (the two lines above) in one program to save an animation created in Python but I didn't succeed! Thanks –  Mar 23 '14 at 17:13
  • @Strömungsmechanik If you have ffmpeg installed correctly, the short answer should work. However, reading your other posts about your animation problem, it doesn't seem that you have the problem discussed here. Have you tried the above tutorial example? – Sascha Mar 31 '14 at 06:56
  • @Sascha Is this bug listed on the matplotlib github site? (I looked and did not find it.) If not, please do report it, so that it gets fixed. – Stretch Apr 14 '14 at 14:04
  • @Stretch I reported the bug some months ago and a fix is on the way. However, it will be published in matplotlib version 1.4.0 for which no due date is set yet. Issue number is #2651. https://github.com/matplotlib/matplotlib/issues/2651 – Sascha Apr 22 '14 at 06:03
  • Adding the first two lines solved my issue! The video isn't playing properly, but that is a separate hurdle. Thanks. – Chris Mueller Jun 02 '15 at 15:47