Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have a very simple code from the matplotlib example:

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. 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

like image 597
Xin Zhang Avatar asked Oct 18 '22 15:10

Xin Zhang


2 Answers

Get it solved by myself! I use conda install to get ffmpeg but when using ffmpeg --version will always say that:

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:

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.

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
like image 191
Xin Zhang Avatar answered Nov 01 '22 18:11

Xin Zhang


I had this problem too. Specifying writer='imagemagick' worked for me.

anim.save('basic_animation.mp4', fps=30, writer='imagemagick')
like image 37
kilojoules Avatar answered Nov 01 '22 19:11

kilojoules