2

У меня есть ноутбук jupyter, который создает анимацию. Он работал над моим старым ноутбуком (xubuntu gnu/linux). Теперь на моем новом ноутбуке (trisquel gnu/linux) он не работает. Это заставляет меня думать, что у меня есть недостающая библиотека или что-то в этом роде, но я не могу ее решить.Анимация в ноутбуке ipython (jupyter) - ValueError: операция ввода-вывода в закрытом файле

В качестве теста я вернулся к учебнику, в котором я узнал, как сделать анимацию для ноутбуков jupyter в первую очередь (http://louistiao.me/posts/notebooks/embedding-matplotlib-animations-in-jupyter-notebooks/). Я получаю ту же проблему, когда я запускаю ячейку кода [7].

Ошибка показана ниже.

Любая помощь в решении этой проблемы будет принята с благодарностью.

Большое спасибо :)

[править 1] Если я пытаюсь anim.save(...) вместо HTML(anim.to_html5_video()), я получаю ту же проблему.

[edit 2] Если я загружаю ноутбук как файл * .py и запускаю его с помощью обычного python (а не ipython), тогда у меня возникает та же проблема.

[edit 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 

ответ

3

Я столкнулся с той же проблемой (на 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 

source

Чтобы установить FFmpeg кодеком x264 включен:

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 

source

+0

@Biggsy, вы смогли решить проблему ? –

+0

ДА! Это сработало! Извиняюсь за задержку - я был так занят другими вещами, что у меня только был шанс попробовать сейчас, но да, это работает. Большое вам спасибо :) – Biggsy

+0

отлично! счастлив, что это сработало –

Смежные вопросы