在anaconda python中保存动画文件时出现“IOError:[Errno 32] Broken pipe”错误

5

我有一个非常简单的代码,来自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,我只需运行以下命令: conda install -c https://conda.anaconda.org/mutirri ffmpeg
3个回答

2

我要自己解决这个问题!我使用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目录下。

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

如果需要将链接移除,请参考以下步骤:

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

1
我也遇到了这个问题。指定 writer='imagemagick' 对我有用。
anim.save('basic_animation.mp4', fps=30, writer='imagemagick')

-1

我认为应该是这样的

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

而不是

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

如果你定义的变量是ani


谢谢,但它仍然报告相同的问题.....我认为可能是我的设置有问题,因为我从http://matplotlib.org/examples/animation/basic_example.html复制了完全相同的示例,但仍然得到相同的报告... - Xin Zhang

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接