Animation ipython(jupyter)笔记本中的动画-值错误:对关闭的文件执行I/O操作

Animation ipython(jupyter)笔记本中的动画-值错误:对关闭的文件执行I/O操作,animation,matplotlib,ipython,ipython-notebook,jupyter-notebook,Animation,Matplotlib,Ipython,Ipython Notebook,Jupyter Notebook,我有一个制作动画的jupyter笔记本。它在我的旧笔记本电脑(xubuntu gnu/linux)上工作。现在在我的新笔记本电脑(trisquel gnu/linux)上,它不工作了。这让我觉得我有一个丢失的图书馆或类似的东西,但我无法解决它 作为测试,我回到了教程,在那里我首先学习了如何制作jupyter笔记本动画()。当我运行代码单元[7]时,我会遇到同样的问题 错误如下所示 如果您能帮助解决这个问题,我们将不胜感激 非常感谢:) [编辑1]如果我尝试anim.save(…)而不是HTML(

我有一个制作动画的jupyter笔记本。它在我的旧笔记本电脑(xubuntu gnu/linux)上工作。现在在我的新笔记本电脑(trisquel gnu/linux)上,它不工作了。这让我觉得我有一个丢失的图书馆或类似的东西,但我无法解决它

作为测试,我回到了教程,在那里我首先学习了如何制作jupyter笔记本动画()。当我运行代码单元[7]时,我会遇到同样的问题

错误如下所示

如果您能帮助解决这个问题,我们将不胜感激

非常感谢:)

[编辑1]如果我尝试
anim.save(…)
而不是
HTML(anim.to\u html5\u video())
,我会遇到同样的问题

[编辑2]如果我将笔记本下载为*.py文件,并使用常规python(而不是ipython)运行它,那么我也会遇到同样的问题

[编辑3]我的ffmpeg安装似乎正在运行,因为我能够从一系列图像手动创建动画。我现在可以使用它作为解决方案,但它非常笨重,HTML(anim.to_html5_video())解决方案应该可以工作,所以仍然需要排序

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-7-5114ccf53b4c> in <module>()
----> 1 HTML(anim.to_html5_video())

/usr/local/lib/python2.7/site-packages/matplotlib/animation.pyc in to_html5_video(self)
   1157                                 bitrate=rcParams['animation.bitrate'],
   1158                                 fps=1000. / self._interval)
-> 1159                 self.save(f.name, writer=writer)
   1160 
   1161             # Now open and base64 encode

/usr/local/lib/python2.7/site-packages/matplotlib/animation.pyc in save(self, filename, writer, fps, dpi, codec, bitrate, extra_args, metadata, extra_anim, savefig_kwargs)
   1011                         # TODO: See if turning off blit is really necessary
   1012                         anim._draw_next_frame(d, blit=False)
-> 1013                     writer.grab_frame(**savefig_kwargs)
   1014 
   1015         # Reconnect signal for first draw if necessary

/usr/local/lib/python2.7/contextlib.pyc in __exit__(self, type, value, traceback)
     33                 value = type()
     34             try:
---> 35                 self.gen.throw(type, value, traceback)
     36                 raise RuntimeError("generator didn't stop after throw()")
     37             except StopIteration, exc:

/usr/local/lib/python2.7/site-packages/matplotlib/animation.pyc in saving(self, *args, **kw)
    254             yield self
    255         finally:
--> 256             self.finish()
    257 
    258     def _run(self):

/usr/local/lib/python2.7/site-packages/matplotlib/animation.pyc in finish(self)
    274     def finish(self):
    275         'Finish any processing for writing the movie.'
--> 276         self.cleanup()
    277 
    278     def grab_frame(self, **savefig_kwargs):

/usr/local/lib/python2.7/site-packages/matplotlib/animation.pyc in cleanup(self)
    309     def cleanup(self):
    310         'Clean-up and collect the process used to write the movie file.'
--> 311         out, err = self._proc.communicate()
    312         self._frame_sink().close()
    313         verbose.report('MovieWriter -- '

/usr/local/lib/python2.7/site-packages/subprocess32.pyc in communicate(self, input, timeout)
    925 
    926         try:
--> 927             stdout, stderr = self._communicate(input, endtime, timeout)
    928         finally:
    929             self._communication_started = True

/usr/local/lib/python2.7/site-packages/subprocess32.pyc in _communicate(self, input, endtime, orig_timeout)
   1711             if _has_poll:
   1712                 stdout, stderr = self._communicate_with_poll(input, endtime,
-> 1713                                                              orig_timeout)
   1714             else:
   1715                 stdout, stderr = self._communicate_with_select(input, endtime,

/usr/local/lib/python2.7/site-packages/subprocess32.pyc in _communicate_with_poll(self, input, endtime, orig_timeout)
   1767             select_POLLIN_POLLPRI = select.POLLIN | select.POLLPRI
   1768             if self.stdout:
-> 1769                 register_and_append(self.stdout, select_POLLIN_POLLPRI)
   1770                 stdout = self._fd2output[self.stdout.fileno()]
   1771             if self.stderr:

/usr/local/lib/python2.7/site-packages/subprocess32.pyc in register_and_append(file_obj, eventmask)
   1746             poller = select.poll()
   1747             def register_and_append(file_obj, eventmask):
-> 1748                 poller.register(file_obj.fileno(), eventmask)
   1749                 self._fd2file[file_obj.fileno()] = file_obj
   1750 

ValueError: I/O operation on closed file
---------------------------------------------------------------------------
ValueError回溯(最近一次调用上次)
在()
---->1个HTML(动画到html5\u视频()
/html5视频中的usr/local/lib/python2.7/site-packages/matplotlib/animation.pyc(self)
1157比特率=rcParams['animation.bitrate'],
1158 fps=1000自我保护(间隔)
->1159 self.save(f.name,writer=写入程序)
1160
1161#现在打开并进行base64编码
/保存中的usr/local/lib/python2.7/site-packages/matplotlib/animation.pyc(self、filename、writer、fps、dpi、codec、比特率、额外参数、元数据、额外动画、savefig\u-kwargs)
1011#TODO:看看是否真的有必要关闭blit
1012动画绘制下一帧(d,blit=False)
->1013书写器。抓取框架(**savefig\U kwargs)
1014
1015#如有必要,重新连接第一次牵引的信号
/usr/local/lib/python2.7/contextlib.pyc in___退出__(self、type、value、traceback)
33值=类型()
34尝试:
--->35自生成抛出(类型、值、回溯)
36 raise RUNTIMERROR(“发电机在抛出()后未停止”)
37除停止迭代外,exc:
/保存中的usr/local/lib/python2.7/site-packages/matplotlib/animation.pyc(self,*args,**kw)
254屈服于自我
255最后:
-->256 self.finish()
257
258 def_运行(自):
/usr/local/lib/python2.7/site-packages/matplotlib/animation.pyc in finish(self)
274 def表面处理(自):
275“完成编写电影的任何处理。”
-->276自我清理()
277
278 def抓斗框架(自身,**保存图):
/清除中的usr/local/lib/python2.7/site-packages/matplotlib/animation.pyc(self)
309 def清理(自):
310“清理并收集用于写入电影文件的进程。”
-->311输出,err=self.\u进程通信()
312自我。_框架_水槽().close()
313冗长的报告('电影编剧--'
/通信中的usr/local/lib/python2.7/site-packages/subprocess32.pyc(self、input、timeout)
925
926尝试:
-->927标准输出,标准输出=自身通信(输入,结束时间,超时)
928最后:
929自通讯开始=真
/usr/local/lib/python2.7/site-packages/subprocess32.pyc in_通信(self、input、endtime、orig_超时)
1711如果有投票:
1712 stdout,stderr=self.\u与轮询通信(输入,结束时间,
->1713(原始超时)
1714其他:
1715标准输出,标准输出=自身。与选择(输入,结束时间,
/usr/local/lib/python2.7/site-packages/subprocess32.pyc in_与_poll通信(self、input、endtime、orig_超时)
1767 select_POLLIN_POLLPRI=select.POLLIN | select.POLLPRI
1768如果self.stdout:
->1769寄存器和附加(self.stdout,选择\u POLLIN\u POLLPRI)
1770 stdout=self.\u fd2输出[self.stdout.fileno()]
1771如果self.stderr:
/usr/local/lib/python2.7/site-packages/subprocess32.pyc在寄存器_和_-append中(文件_obj,事件掩码)
1746 poller=select.poll()
1747 def寄存器和附加(文件对象、事件掩码):
->1748轮询器寄存器(文件_obj.fileno(),事件掩码)
1749 self.\u fd2文件[文件\u obj.fileno()]=文件\u obj
1750
ValueError:对关闭的文件执行I/O操作
我遇到了同样的问题(在mac os 10.12.2上),并通过重新安装
ffmpeg
并启用x264编解码器修复了它,而
to_html5_video()
函数需要将动画转换为html5

要安装x264,请执行以下操作:

cd /my/path/where/i/keep/compiled/stuff
git clone git://git.videolan.org/x264.git
cd x264
./configure --enable-static --enable-shared
make
make install
ldconfig # note: use for linux, not necessary for mac

要在启用x264编解码器的情况下安装ffmpeg,请执行以下操作:

cd /my/path/where/i/keep/compiled/stuff
git clone http://source.ffmpeg.org/git/ffmpeg.git
cd ffmpeg
./configure --enable-gpl --enable-libx264
make
make install
ldconfig # note: use for linux, not necessary for mac

@Biggsy,你能解决这个问题吗?是的!它成功了!为延迟道歉-我一直忙于其他事情,我现在才有机会尝试一下,但是是的,它成功了。非常感谢:)