"IOError: [Errno 32] Broken pipe" when saving animation files in anaconda python

"IOError: [Errno 32] Broken pipe" when saving animation files in anaconda python

我有一个来自 matplotlib 示例的非常简单的代码:

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation

fig, ax = plt.subplots()
line, = ax.plot(np.random.rand(10))
ax.set_ylim(0, 1)

def update(data):
   line.set_ydata(data)
return line,

def data_gen():
   while True: yield np.random.rand(10)

ani = animation.FuncAnimation(fig, update, data_gen, interval=1000)
anim.save('basic_animation.mp4', fps=30)
plt.show()

如果我不使用 anim.save() 函数,一切都是正确的。但是,当我要保存它时,它会报告:

IOError                                   Traceback (most recent call last)
<ipython-input-6-8948bc3b3f5c> in <module>()
     16 
     17 ani = animation.FuncAnimation(fig, update, data_gen, interval=1000)
---> 18 anim.save('basic_animation.mp4', fps=30)
     19 plt.show()

....(traceback details are omitted here) 

/home/xin/anaconda2/lib/python2.7/site-packages/matplotlib/backends/backend_agg.pyc in print_raw(self, filename_or_obj, *args, **kwargs)
    517             close = False
    518         try:
--> 519             fileobj.write(renderer._renderer.buffer_rgba())
    520         finally:
    521             if close:

IOError: [Errno 32] Broken pipe

我该如何解决?或者还有其他方法可以将动画保存到文件吗?

补充:安装ffmpeg,我只是运行: 康达安装-c https://conda.anaconda.org/mutirri ffmpeg

我觉得应该是

ani.save('basic_animation.mp4', fps=30)

而不是

anim.save('basic_animation.mp4', fps=30)

如果你定义的变量是ani

自己解决!我使用 conda install 来获取 ffmpeg,但是在使用 ffmpeg 时 --version 总是会说:

libssl.so.10: cannot open shared object file: No such file or directory

所以我使用:

sudo ln -s /home/xin/anaconda2/lib/libssl.so.1.0.0 libssl.so.10

然后得到关于libcrypto.so.10的类似问题,所以我使用:

sudo ln -s /home/xin/anaconda2/lib/libcrypto.so.1.0.0 libcrypto.so.10

两个文件在/lib/x86_64-linux-gnu.

现在一切正常!!我知道有些人也有类似的问题,所以记录在这里。

以后如果需要去掉link:

cd /lib/x86_64-linux-gnu
sudo unlink libssl.so.10
sudo unlink libcrypto.so.10

我也有这个问题。指定 writer='imagemagick' 对我有用。

anim.save('basic_animation.mp4', fps=30, writer='imagemagick')