Skip to content

FuncAnimation.save throws TypeError #16965

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rmeno12 opened this issue Mar 30, 2020 · 18 comments
Closed

FuncAnimation.save throws TypeError #16965

rmeno12 opened this issue Mar 30, 2020 · 18 comments
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. topic: animation
Milestone

Comments

@rmeno12
Copy link

rmeno12 commented Mar 30, 2020

Bug report

Bug summary

I was trying to use FuncAnimation's save method to save an animation that I'd created to a .mp4 file, but it threw a TypeError when I ran my code (the animation displays fine with plt.show()).

Code for reproduction

import matplotlib.pyplot as plt
import matplotlib.animation as animation
import random

fig = plt.figure()
ax1 = fig.add_subplot(1, 1, 1)
x = [random.randint(0, 10) for _ in range(5)]
y = [random.randint(0, 10) for _ in range(5)]


def ani_func(i):
    x.append(random.randint(0, 10))
    y.append(random.randint(0, 10))
    ax1.clear()
    ax1.plot(x, y)

ani = animation.FuncAnimation(fig, ani_func, frames=10, repeat=False)
plt.show()
ani.save('test.mp4')

Actual outcome

The animation itself works fine in plt.show() producing this image as the last frame as expected:
image

However, the animation doesn't save to test.mp4 and instead throws a TypeError. I have included the entire traceback below.

Traceback (most recent call last):
  File ".\disease_simulation\graphout.py", line 19, in <module>
    ani.save('test.mp4')
  File "C:\Users\menon\Desktop\disease-simulation\env\lib\site-packages\matplotlib\animation.py", line 1102, in save
    alt_writer = next(writers, None)
TypeError: 'MovieWriterRegistry' object is not an iterator

Matplotlib version

  • Operating system: Windows 10
  • Matplotlib version: 3.2.1
  • Matplotlib backend (print(matplotlib.get_backend())): TkAgg
  • Python version: 3.6.8

Matplotlib was installed via pip in a venv.

@anntzer anntzer added topic: animation Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. labels Mar 30, 2020
@anntzer anntzer added this to the v3.2.2 milestone Mar 30, 2020
@tacaswell
Copy link
Member

Thanks for the report @rmeno12 . We have a PR to fix the exception, but you will still have the problem that you do not have ffmpeg installed so will not be able to create an mp4 for you.

@timhoffm
Copy link
Member

Closed by #16965.

@gemerden
Copy link

gemerden commented May 4, 2020

I seem to be having the same problem, any idea when the fix will come out? Is there any workaround? Is there an older version without this problem? I am using ArtistAnimation with the same problem on version 3.2.1.

@QuLogic
Copy link
Member

QuLogic commented May 4, 2020

3.2.2 will be out with the release candidate for 3.3.0, either end of this week or some time next week.

@bluesammer
Copy link

Its still not around.

@tacaswell
Copy link
Member

We are a mostly volunteer organization and sometimes release dates slip. Any help clearing the remaining issues for 3.2.2 and 3.3.0 would be appreciated and expedite the process.

https://github.com/matplotlib/matplotlib/milestone/52
https://github.com/matplotlib/matplotlib/milestone/48

jftsang added a commit to jftsang/mdpmflc that referenced this issue Jul 5, 2020
Part of <#7>. The current strategy is to produce .gif files locally and
then convert them to .webm and then serve the .webm's. There is
currently a bug with matplotlib that mp4 cannot be created:
<matplotlib/matplotlib#16965>.

This strategy is *very* slow. As with the rest of the graphics (and also
with the MercuryPostprocessing library), the massive bottleneck is
reading the .data. files, which are read in their entirety even if you
want only a few thousand lines. Since the process is so long and costly,
there is the risk of submitting two requests, and the second one
overwriting the first, and duplicating the effort. Maybe use some sort
of locking.

More importantly, use queueing (<#24>).
@stevenlis
Copy link

I'm using 3.2.1 and already pip install ffmpeg but when I run the following code

import matplotlib.animation as manimation
manimation.writers.list()

I still only got ['pillow', 'html']. Is there an easy way to install ffmpeg on Windows rather than setting system var and am I missing something?

@tacaswell
Copy link
Member

@StevenLi-DS This fix is on 3.2.2 to get the better fallback behavior, but that won't solve your installation problem.

ffmpeg is usually a system dependency (the ffmpeg package on pypi is a python wrapper that calls out via sub-process). I am not a regular windows user, but I suggest starting at https://ffmpeg.org/download.html

@ndavoudi
Copy link

ndavoudi commented Dec 1, 2020

I am using matplotlib 3.3.2 on windows and still get the error "TypeError: 'str' object is not callable" when using animation save. Any help would be appreciated :)

@dopplershift
Copy link
Contributor

Can you open a new issue with a minimal example that causes the issue?

@pguthrey
Copy link

I'm getting the same issue as @ndavoudi

@jklymak
Copy link
Member

jklymak commented Dec 19, 2020

We can't fix an error if we can't trigger it. Can someone provide a MWE so we can try and fix?

@pguthrey
Copy link

pguthrey commented Dec 20, 2020

I think this is just related to ' fallback behavior', perhaps? When reinstalled ffmpeg the issue was resolved. So there is something up with the pillow fallback perhaps?

So the MWE would be to uninstall ffmpeg and see if the fallback behavior acts as expected?

Anyway the issue is resolved for me currently.

@bcalvr
Copy link

bcalvr commented Mar 23, 2021

I am getting the same "TypeError: 'MovieWriterRegistry' object is not an iterator" message, does anyone know if this bug has now been fixed and therefore whether it's a problem at my end?

@jklymak
Copy link
Member

jklymak commented Mar 23, 2021

@bcalvr if it is exactly the same repro as the original issue we can re-open. If its different, then please open a new issue with the reproducible example. Also it looks like stating whether you have ffmpeg or not may be helpful. Perhaps we have a broken untested fallback?

@bcalvr
Copy link

bcalvr commented Mar 24, 2021

I think I have managed to solve the problem - it was to do with the location of my ffmpeg installation. Thank you for the response though! I am now able to export animations to video files, but I am still struggling with getting them to play inline in Atom!

@liqinglin54951
Copy link

Installation of FFmpeg in anaconda(from https://blog.csdn.net/Linli522362242/article/details/121313449):
conda install -c conda-forge ffmpeg
`import matplotlib.pyplot as plt
import matplotlib.animation as animation
import random
from IPython.display import HTML

fig = plt.figure()
ax1 = fig.add_subplot(1, 1, 1)
x = [random.randint(0, 10) for _ in range(5)]
y = [random.randint(0, 10) for _ in range(5)]

def ani_func(i):
x.append(random.randint(0, 10))
y.append(random.randint(0, 10))
ax1.clear()
ax1.plot(x, y)

ani = animation.FuncAnimation(fig, ani_func, frames=10, repeat=False)
plt.show()
ani.save('test2.mp4')
HTML( ani.to_html5_video() )`
image

image

@liqinglin54951
Copy link

I am using matplotlib 3.3.2 on windows and still get the error "TypeError: 'str' object is not callable" when using animation save. Any help would be appreciated :)

since you didn't install FFmpeg in anaconda, see detail solutions:https://blog.csdn.net/Linli522362242/article/details/121313449

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. topic: animation
Projects
None yet
Development

No branches or pull requests