質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Jupyter

Jupyter (旧IPython notebook)は、Notebook形式でドキュメント作成し、プログラムの記述・実行、その実行結果を記録するツールです。メモの作成や保存、共有、確認などもブラウザ上で行うことができます。

OpenAI Gym

OpenAI Gymは、強化学習を開発・強化するためのシミュレーション環境です。強化学習における実験や評価環境などを標準化し提供することを目的としています。さらに、結果をアップロードしたり、他の人の実行結果や実装を見ることも可能です。

Anaconda

Anacondaは、Python本体とPythonで利用されるライブラリを一括でインストールできるパッケージです。環境構築が容易になるため、Python開発者間ではよく利用されており、商用目的としても利用できます。

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

Q&A

1回答

3496閲覧

JSAnimationのAttributeError:”: 'HTMLWriter' object has no attribute '_temp_names'”を解決したい

satou_sumito

総合スコア0

Jupyter

Jupyter (旧IPython notebook)は、Notebook形式でドキュメント作成し、プログラムの記述・実行、その実行結果を記録するツールです。メモの作成や保存、共有、確認などもブラウザ上で行うことができます。

OpenAI Gym

OpenAI Gymは、強化学習を開発・強化するためのシミュレーション環境です。強化学習における実験や評価環境などを標準化し提供することを目的としています。さらに、結果をアップロードしたり、他の人の実行結果や実装を見ることも可能です。

Anaconda

Anacondaは、Python本体とPythonで利用されるライブラリを一括でインストールできるパッケージです。環境構築が容易になるため、Python開発者間ではよく利用されており、商用目的としても利用できます。

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

0グッド

0クリップ

投稿2020/07/26 16:18

前提・実現したいこと

Windows10にanaconda3をインストールし、Jupter Notebook6.0.3で実行しています。

ここに質問の内容を詳しく書いてください。
(例)PHP(CakePHP)で●●なシステムを作っています。
JSAnimationの機能を実装中に、
"AttributeError:'HTMLWriter' object has no attribute '_temp_names'”エラーが発生しています。

発生している問題・エラーメッセージ


AttributeError Traceback (most recent call last)
<ipython-input-7-135fd70ab5ea> in <module>
1 # main
2 cartpole_env = Environment()
----> 3 cartpole_env.run()

<ipython-input-6-d95a468157b1> in run(self)
54
55 if is_episode_final is True: # 最終試行では動画を保存と描画
---> 56 display_frames_as_gif(frames)
57 break
58

<ipython-input-2-d7995b48f897> in display_frames_as_gif(frames)
23
24 anim.save('movie_cartpole.mp4') # 動画のファイル名と保存です
---> 25 display(display_animation(anim, default_mode='loop'))
26

~\anaconda3\lib\site-packages\JSAnimation\IPython_display.py in display_animation(anim, **kwargs)
84 """Display the animation with an IPython HTML object"""
85 from IPython.display import HTML
---> 86 return HTML(anim_to_html(anim, **kwargs))
87
88

~\anaconda3\lib\site-packages\JSAnimation\IPython_display.py in anim_to_html(anim, fps, embed_frames, default_mode)
72 #with tempfile.NamedTemporaryFile(suffix='.html') as f:
73 with _NameOnlyTemporaryFile(suffix='.html') as f:
---> 74 anim.save(f.name, writer=HTMLWriter(fps=fps,
75 embed_frames=embed_frames,
76 default_mode=default_mode))

~\anaconda3\lib\site-packages\matplotlib\animation.py in save(self, filename, writer, fps, dpi, codec, bitrate, extra_args, metadata, extra_anim, savefig_kwargs, progress_callback)
1150 progress_callback(frame_number, total_frames)
1151 frame_number += 1
-> 1152 writer.grab_frame(**savefig_kwargs)
1153
1154 # Reconnect signal for first draw if necessary

~\anaconda3\lib\contextlib.py in exit(self, type, value, traceback)
118 if type is None:
119 try:
--> 120 next(self.gen)
121 except StopIteration:
122 return False

~\anaconda3\lib\site-packages\matplotlib\animation.py in saving(self, fig, outfile, dpi, *args, **kwargs)
230 yield self
231 finally:
--> 232 self.finish()
233
234

~\anaconda3\lib\site-packages\matplotlib\animation.py in finish(self)
526 # Call run here now that all frame grabbing is done. All temp files
527 # are available to be assembled.
--> 528 self._run()
529 MovieWriter.finish(self) # Will call clean-up
530

~\anaconda3\lib\site-packages\JSAnimation\html_writer.py in _run(self)
321 of.write(JS_INCLUDE)
322 of.write(DISPLAY_TEMPLATE.format(id=self.new_id(),
--> 323 Nframes=len(self._temp_names),
324 fill_frames=fill_frames,
325 interval=interval,

AttributeError: 'HTMLWriter' object has no attribute '_temp_names'

該当のソースコード

Python3.7

試したこと

ここに問題に対して試したことを記載してください。

補足情報(FW/ツールのバージョンなど)

ここにより詳細な情報を記載してください。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

Solution 1

The first solution is a hack. You just need to make JSAnimation package compatible with the newer versions of matplotlib. And it's much easier than you might expect.

Find the JSAnimation package in your Anaconda installation. For the case of the base environment it might be:

C:\ProgramData\Anaconda3\Lib\site-packages\JSAnimation

For other environments it will be something like:

C:\ProgramData\Anaconda3\envs\your_env_name\Lib\site-packages\JSAnimation

Open html_writer.py file with Notepad++ or any other text editor, but not with PyCharm, as it will not allow you to modify a library file.

The only things you need to change are:

  • Change self._temp_names to self._temp_paths.

  • Change return ('', '') to return (''.encode('utf-8'), ''.encode('utf-8')) to return a tuple of byte arrays instead of strings.

Save the file (you will need admin privileges), run the Jupyter. It should work now. It worked for me.

For convenience here's code of the _run method in html_writer.py after changes:

def _run(self): # make a ducktyped subprocess standin # this is called by the MovieWriter base class, but not used here. class ProcessStandin(object): returncode = 0 def communicate(self): return (''.encode('utf-8'), ''.encode('utf-8')) self._proc = ProcessStandin() # save the frames to an html file if self.embed_frames: fill_frames = _embedded_frames(self._saved_frames, self.frame_format) else: # temp names is filled by FileMovieWriter fill_frames = _included_frames(self._temp_paths, self.frame_format) mode_dict = dict(once_checked='', loop_checked='', reflect_checked='') mode_dict[self.default_mode + '_checked'] = 'checked' interval = int(1000. / self.fps) with open(self.outfile, 'w') as of: of.write(JS_INCLUDE) of.write(DISPLAY_TEMPLATE.format(id=self.new_id(), Nframes=len(self._temp_paths), fill_frames=fill_frames, interval=interval, icons=_Icons(), **mode_dict))

Solution 2

This is a cleaner solution. As JSAnimation was merged into newer matplotlib it is better to use the integrated version. The solution is as follows:

  1. Open pong_utils.py.

  2. Find animate_frames method.

  3. Just before this method add:

def display_animation(anim): plt.close(anim._fig) return HTML(anim.to_jshtml())
  1. Change
display(display_animation(fanim, default_mode='once'))

to

display(display_animation(fanim))
  1. You can remove the import:
from JSAnimation.IPython_display import display_animation

That's it.

投稿2021/02/14 11:13

PiotrZiolo

総合スコア10

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問