[英]“IOError: [Errno 32] Broken pipe” when saving animation files in anaconda python
I have a very simple code from the matplotlib example: 我有一个来自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()
Everything is right if I do not use anim.save() function. 如果我不使用anim.save()函数,一切都是正确的。 However, when I want to save it, it would report: 但是,当我想保存它时,它会报告:
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
How can I fix it? 我该如何解决? Or are there any other ways to save animation to a file? 或者还有其他方法可以将动画保存到文件中吗?
Supplement: To install ffmpeg, I just run: conda install -c https://conda.anaconda.org/mutirri ffmpeg 补充:要安装ffmpeg,我只需运行:conda install -c https://conda.anaconda.org/mutirri ffmpeg
Get it solved by myself! 让我自己解决! I use conda install to get ffmpeg but when using ffmpeg --version will always say that: 我使用conda install来获取ffmpeg,但是当使用ffmpeg --version时总会说:
libssl.so.10: cannot open shared object file: No such file or directory
so I use: 所以我使用:
sudo ln -s /home/xin/anaconda2/lib/libssl.so.1.0.0 libssl.so.10
Then get similar problem about libcrypto.so.10, so I use: 然后得到关于libcrypto.so.10的类似问题,所以我使用:
sudo ln -s /home/xin/anaconda2/lib/libcrypto.so.1.0.0 libcrypto.so.10
The two files are in /lib/x86_64-linux-gnu. 这两个文件位于/ lib / x86_64-linux-gnu中。
Now things work!! 现在一切正常!! I know some people also have similar problems, so I record it here. 我知道有些人也有类似的问题,所以我在这里记录。
In future, if need to remove the link: 将来,如果需要删除链接:
cd /lib/x86_64-linux-gnu
sudo unlink libssl.so.10
sudo unlink libcrypto.so.10
I think it should be 我认为应该是
ani.save('basic_animation.mp4', fps=30)
and not 并不是
anim.save('basic_animation.mp4', fps=30)
if your defined variable is ani
如果你定义的变量是ani
I had this problem too. 我也有这个问题。 Specifying writer='imagemagick'
worked for me. 指定writer='imagemagick'
为我工作。
anim.save('basic_animation.mp4', fps=30, writer='imagemagick')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.