alifelab / alife_book_src

「作って動かすALife - 実装を通した人工生命モデル理論入門」サンプルコード
235 stars 114 forks source link

gray_scott.pyが動かない #29

Open 079hide opened 5 years ago

079hide commented 5 years ago

お知恵をお借りしたく投稿させて頂きました。

■問題となっている現象に関して 第2章にある以下のコマンドを打つと、ウィンドウは出現するのですが、描画されません。 $ python gray_scott.py

実行後のターミナルは、以下のようになります。 repeatしてエラーを出し続けるので、Ctrl+C(KeyboardInterrupt)で強制終了しました。

―――――――――――――――――――――――――――――――――――――――――――

WARNING: Traceback (most recent call last): File "gray_scott.py", line 53, in visualizer.update(u) File "..\alifebook_lib\visualizers\matrix_visualizer.py", line 36, in update app.process_events() File "C:\Users\SONY\Anaconda3\envs\alife\lib\site-packages\vispy\app_default_app.py", line 79, in process_events return default_app.process_events() File "C:\Users\SONY\Anaconda3\envs\alife\lib\site-packages\vispy\app\application.py", line 78, in process_events return self._backend._vispy_process_events() File "C:\Users\SONY\Anaconda3\envs\alife\lib\site-packages\vispy\app\backends_qt.py", line 222, in _vispy_process_events app.processEvents() File "C:\Users\SONY\Anaconda3\envs\alife\lib\site-packages\vispy\app\backends_qt.py", line 436, in event out = super(QtBaseCanvasBackend, self).event(ev) File "C:\Users\SONY\Anaconda3\envs\alife\lib\site-packages\vispy\app\backends_qt.py", line 708, in paintGL self._vispy_canvas.events.draw(region=None) File "C:\Users\SONY\Anaconda3\envs\alife\lib\site-packages\vispy\util\event.py", line 455, in call self._invoke_callback(cb, event) File "C:\Users\SONY\Anaconda3\envs\alife\lib\site-packages\vispy\util\event.py", line 475, in _invoke_callback self, cb_event=(cb, event)) << caught exception here: >> File "C:\Users\SONY\Anaconda3\envs\alife\lib\site-packages\vispy\util\event.py", line 471, in _invoke_callback cb(event) File "..\alifebook_lib\visualizers\matrix_visualizer.py", line 28, in _on_draw self._render_program.draw(gloo.gl.GL_TRIANGLE_STRIP) File "C:\Users\SONY\Anaconda3\envs\alife\lib\site-packages\vispy\gloo\program.py", line 470, in draw canvas.context.flush_commands() File "C:\Users\SONY\Anaconda3\envs\alife\lib\site-packages\vispy\gloo\context.py", line 170, in flush_commands self.shared.parser.parse([('CURRENT', 0)]) File "C:\Users\SONY\Anaconda3\envs\alife\lib\site-packages\vispy\gloo\glir.py", line 477, in parse self._parse(command) File "C:\Users\SONY\Anaconda3\envs\alife\lib\site-packages\vispy\gloo\glir.py", line 404, in _parse self._gl_initialize() File "C:\Users\SONY\Anaconda3\envs\alife\lib\site-packages\vispy\gloo\glir.py", line 502, in _gl_initialize if this_version < '2.1': File "C:\Users\SONY\Anaconda3\envs\alife\lib\distutils\version.py", line 52, in lt c = self._cmp(other) File "C:\Users\SONY\Anaconda3\envs\alife\lib\distutils\version.py", line 335, in _cmp if self.version == other.version: AttributeError: 'LooseVersion' object has no attribute 'version' ERROR: Invoking <bound method MatrixVisualizer._on_draw of <alifebook_lib.visualizers.matrix_visualizer.MatrixVisualizer object at 0x0000021568F31F98>> for DrawEvent WARNING: Traceback (most recent call last): File "gray_scott.py", line 53, in visualizer.update(u) File "..\alifebook_lib\visualizers\matrix_visualizer.py", line 36, in update app.process_events() File "C:\Users\SONY\Anaconda3\envs\alife\lib\site-packages\vispy\app_default_app.py", line 79, in process_events return default_app.process_events() File "C:\Users\SONY\Anaconda3\envs\alife\lib\site-packages\vispy\app\application.py", line 78, in process_events return self._backend._vispy_process_events() File "C:\Users\SONY\Anaconda3\envs\alife\lib\site-packages\vispy\app\backends_qt.py", line 222, in _vispy_process_events app.processEvents() File "C:\Users\SONY\Anaconda3\envs\alife\lib\site-packages\vispy\app\backends_qt.py", line 436, in event out = super(QtBaseCanvasBackend, self).event(ev) File "C:\Users\SONY\Anaconda3\envs\alife\lib\site-packages\vispy\app\backends_qt.py", line 708, in paintGL self._vispy_canvas.events.draw(region=None) File "C:\Users\SONY\Anaconda3\envs\alife\lib\site-packages\vispy\util\event.py", line 455, in call self._invoke_callback(cb, event) File "C:\Users\SONY\Anaconda3\envs\alife\lib\site-packages\vispy\util\event.py", line 475, in _invoke_callback self, cb_event=(cb, event)) << caught exception here: >> File "C:\Users\SONY\Anaconda3\envs\alife\lib\site-packages\vispy\gloo\gl_gl2.py", line 269, in glCreateProgram nativefunc = glCreateProgram._native AttributeError: 'function' object has no attribute '_native'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Users\SONY\Anaconda3\envs\alife\lib\site-packages\vispy\gloo\gl\gl2.py", line 72, in _get_gl_func func = getattr(_lib, name) File "C:\Users\SONY\Anaconda3\envs\alife\lib\ctypes__init.py", line 361, in getattr func = self.getitem(name) File "C:\Users\SONY\Anaconda3\envs\alife\lib\ctypes\init.py", line 366, in getitem__ func = self._FuncPtr((name_or_ordinal, self)) AttributeError: function 'glCreateProgram' not found

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Users\SONY\Anaconda3\envs\alife\lib\site-packages\vispy\util\event.py", line 471, in _invoke_callback cb(event) File "C:\Users\SONY\Anaconda3\envs\alife\lib\site-packages\vispy\gloo\context.py", line 171, in flush_commands self.glir.flush(self.shared.parser) File "C:\Users\SONY\Anaconda3\envs\alife\lib\site-packages\vispy\gloo\glir.py", line 232, in flush self._shared.flush(parser) File "C:\Users\SONY\Anaconda3\envs\alife\lib\site-packages\vispy\gloo\glir.py", line 146, in flush parser.parse(self._filter(self.clear(), parser)) File "C:\Users\SONY\Anaconda3\envs\alife\lib\site-packages\vispy\gloo\glir.py", line 477, in parse self._parse(command) File "C:\Users\SONY\Anaconda3\envs\alife\lib\site-packages\vispy\gloo\glir.py", line 417, in _parse self.objects[id] = klass(self, id_) File "C:\Users\SONY\Anaconda3\envs\alife\lib\site-packages\vispy\gloo\glir.py", line 546, in init self.create() File "C:\Users\SONY\Anaconda3\envs\alife\lib\site-packages\vispy\gloo\glir.py", line 600, in create self._handle = gl.glCreateProgram() File "C:\Users\SONY\Anaconda3\envs\alife\lib\site-packages\vispy\gloo\gl_gl2.py", line 271, in glCreateProgram nativefunc = glCreateProgram._native = _get_gl_func("glCreateProgram", ctypes.c_uint, ()) File "C:\Users\SONY\Anaconda3\envs\alife\lib\site-packages\vispy\gloo\gl\gl2.py", line 87, in _get_gl_func raise RuntimeError('Using %s with no OpenGL context.' % name) RuntimeError: Using glCreateProgram with no OpenGL context. ERROR: Invoking <bound method GLContext.flush_commands of <GLContext at 0x2156db1de80>> for DrawEvent ERROR: Invoking <bound method MatrixVisualizer._on_draw of <alifebook_lib.visualizers.matrix_visualizer.MatrixVisualizer object at 0x0000021568F31F98>> repeat 2 ERROR: Invoking <bound method GLContext.flush_commands of <GLContext at 0x2156db1de80>> repeat 2 ERROR: Invoking <bound method MatrixVisualizer._on_draw of <alifebook_lib.visualizers.matrix_visualizer.MatrixVisualizer object at 0x0000021568F31F98>> repeat 4 ERROR: Invoking <bound method GLContext.flush_commands of <GLContext at 0x2156db1de80>> repeat 4 ERROR: Invoking <bound method MatrixVisualizer._on_draw of <alifebook_lib.visualizers.matrix_visualizer.MatrixVisualizer object at 0x0000021568F31F98>> repeat 8 ERROR: Invoking <bound method GLContext.flush_commands of <GLContext at 0x2156db1de80>> repeat 8 ERROR: Invoking <bound method MatrixVisualizer._on_draw of <alifebook_lib.visualizers.matrix_visualizer.MatrixVisualizer object at 0x0000021568F31F98>> repeat 16 ERROR: Invoking <bound method GLContext.flush_commands of <GLContext at 0x2156db1de80>> repeat 16 ERROR: Invoking <bound method MatrixVisualizer._on_draw of <alifebook_lib.visualizers.matrix_visualizer.MatrixVisualizer object at 0x0000021568F31F98>> repeat 32 ERROR: Invoking <bound method GLContext.flush_commands of <GLContext at 0x2156db1de80>> repeat 32 ERROR: Invoking <bound method MatrixVisualizer._on_draw of <alifebook_lib.visualizers.matrix_visualizer.MatrixVisualizer object at 0x0000021568F31F98>> repeat 64 ERROR: Invoking <bound method GLContext.flush_commands of <GLContext at 0x2156db1de80>> repeat 64 ERROR: Invoking <bound method MatrixVisualizer._on_draw of <alifebook_lib.visualizers.matrix_visualizer.MatrixVisualizer object at 0x0000021568F31F98>> repeat 128 ERROR: Invoking <bound method GLContext.flush_commands of <GLContext at 0x2156db1de80>> repeat 128 Traceback (most recent call last): File "gray_scott.py", line 44, in np.roll(u, 1, axis=1) + np.roll(u, -1, axis=1) - 4u) / (dxdx) KeyboardInterrupt

■OS, python, モジュールなどの実行環境に関して 以下をターミナルから実行し、出力された各種環境情報です。 $ python -c "import vispy; print(vispy.sys_info())"

―――――――――――――――――――――――――――――――――――――――――――

Platform: Windows-10-10.0.17134-SP0 Python: 3.6.7 |Anaconda, Inc.| (default, Oct 28 2018, 19:44:12) [MSC v.1915 64 bit (AMD64)] NumPy: 1.15.4 Backend: PyQt5 pyqt4: None pyqt5: ('PyQt5', '5.9.2', '5.9.6') pyside: None pyglet: None glfw: None sdl2: None wx: None egl: None osmesa: None _test: None

GL version: '' MAX_TEXTURE_SIZE: () Extensions: ''

―――――――――――――――――――――――――――――――――――――――――――

また、他のパッケージのバージョン情報です。

―――――――――――――――――――――――――――――――――――――――――――

packages in environment at C:\Users\SONY\Anaconda3\envs\alife:

#

Name Version Build Channel

_tflow_select 2.2.0 eigen
absl-py 0.6.1 py36_0
astor 0.7.1 py36_0
blas 1.0 mkl
ca-certificates 2018.03.07 0
certifi 2018.10.15 py36_0
freetype 2.9.1 ha9979f8_1
gast 0.2.0 py36_0
grpcio 1.14.1 py36h5c4b210_0
h5py 2.8.0 py36h3bdd7fb_2
hdf5 1.10.2 hac2f561_1
icc_rt 2017.0.4 h97af966_0
icu 58.2 ha66f8fd_1
intel-openmp 2019.1 144
jpeg 9b hb83a4c4_2
keras 2.2.4 0
keras-applications 1.0.6 py36_0
keras-base 2.2.4 py36_0
keras-preprocessing 1.0.5 py36_0
libpng 1.6.35 h2a8f88b_0
libprotobuf 3.6.1 h7bd577a_0
libtiff 4.0.9 h36446d0_2
markdown 3.0.1 py36_0
mkl 2018.0.3 1
mkl_fft 1.0.6 py36hdbbee80_0
mkl_random 1.0.1 py36h77b88f5_1
numpy 1.15.4 py36ha559c80_0
numpy-base 1.15.4 py36h8128ebf_0
olefile 0.46 py36_0
openssl 1.0.2p hfa6e2cd_0
pillow 5.3.0 py36hdc69c19_0
pip 18.1 py36_0
protobuf 3.6.1 py36h33f27b4_0
pyqt 5.9.2 py36h6538335_2
python 3.6.7 h33f27b4_1
pyyaml 3.13 py36hfa6e2cd_0
qt 5.9.6 vc14h1e9a669_2
scipy 1.1.0 py36h4f6bf74_1
setuptools 40.6.2 py36_0
sip 4.19.8 py36h6538335_0
six 1.11.0 py36_1
sqlite 3.25.3 he774522_0
tensorboard 1.12.0 py36he025d50_0
tensorflow 1.12.0 eigen_py36h67ac661_0
tensorflow-base 1.12.0 eigen_py36h45df0d8_0
termcolor 1.1.0 py36_1
tk 8.6.8 hfa6e2cd_0
vc 14.1 h0510ff6_4
vispy 0.5.3 py36hee6b756_0
vs2015_runtime 14.15.26706 h3a45250_0
werkzeug 0.14.1 py36_0
wheel 0.32.3 py36_0
wincertstore 0.2 py36h7fe50ca_0
yaml 0.1.7 hc54c509_2
zlib 1.2.11 h62dcd97_3

■その他環境に関して CPUの情報を記載します。

Xoreax CPU Info

Vendor String GenuineIntel Vendor Intel Brand String Intel(R) Pentium(R) CPU P6200 @ 2.13GHz Frequency 2128 MHz Physical CPUs 1 Logical CPUs 2 CPU Cores (guess) 2 CPU Config (guess) Single CPU, Dual Core, No Hyperthreading

tomotomo47 commented 5 years ago

答えになってなくて恐縮ですが、同じくgray_scott.pyが動かず、他のプログラムも動かないといいますか、中が透けたウィンドウ枠が出るだけです。windows7です。どなたか解決された方はいらっしゃらないでしょうか?

mitsuyoshi-yamazaki commented 5 years ago

Windowsで上記のエラーでしたらこのissueと同じ原因なのではないでしょうか。 https://github.com/vispy/vispy/issues/1503

こちらでは pyqtのバージョン4を使用したらvispyが動いたという報告があります。

手順としては以下のようになるでしょうか(私の環境ではエラーが出ないので、動作未検証です

$ conda clean --all 
$ conda install "pyqt<5"
$ python gray_scott.py

# ImportError : No module named 'xxx' が出たら $ conda install xxx して潰していく
tomotomo47 commented 5 years ago

コメントありがとうございました。 自分のPyQtもVer.5でしたので可能性が大きいと思いますが、pyqt4はconda installではインストールできませんでした。 pyqt4はソースファイルしかネットにないので、ダウンロードしてコンパイルして、condaにつなげる pyではなくてC言語で自作する pyqt4でも動くようにしてみる? というのの、一番楽そうな方法で試してみようと思います。 vispyのバージョンを変えてみるとかでも良いかも。

mitsuyoshi-yamazaki commented 5 years ago

alifebook_libのソースも読んでみたのですが、vispyで使用するバックエンドを PyQt5 に明示的に指定しているので、PyQt4をインストールする場合はこちらも書き換える必要があると思います。 https://github.com/alifelab/alife_book_src/blob/master/alifebook_lib/__init__.py#L2

本書のコードがPyQt4でも正常に動くのか、というのは別の問題なのですが、異なるバックエンドを統一的なインターフェースで扱えるようにすることがvispyの目的なら、動いてくれるのではないかと期待しています。

mitsuyoshi-yamazaki commented 5 years ago

@tomotomo47 PyQt4を使用するのとは別のアプローチです

@079hide さんが挙げているのと同じ状況、つまり

RuntimeError: Using xxxx with no OpenGL context. エラーが発生していて、かつ

$ python -c "import vispy; print(vispy.sys_info())" した際に GL version が表示されない場合( GL version: '' のように:以下が空の場合 )は、vispyが使用するOpenGLターゲットを変更してみるのが有効かもしれません。

方法

https://github.com/alifelab/alife_book_src/blob/master/alifebook_lib/__init__.py#L2

vispy.use('PyQt5') を以下のそれぞれに変更して実行してみてください。

vispy.use('PyQt5', 'es2') vispy.use('PyQt5', 'gl+') vispy.use('PyQt5', 'pyopengl2')

解説

alifebook_libでは vispy.use() 呼び出し時に第二引数を省略しているため、ターゲットがデフォルトの gl2 固定になっているところを、別のターゲットに変更してみる試みです。

お使いの環境で gl2 ターゲットが動作しないので問題が起きているのではないかという仮説です。 そうだとすれば es2 - Use the ES2 library (Angle/DirectX on Windows) とあるので、Windows環境では vispy.use('PyQt5', 'es2') と書き換えれば動くのではないかと思います。

ターゲット一覧と解説: https://github.com/vispy/vispy/blob/master/vispy/gloo/gl/__init__.py#L112-L118

tomotomo47 commented 5 years ago

いろいろ助言頂きありがとうございます。 本によると、PyQt5を前提にしていると書いてあるので、PyQt4出ないと動かないというのは違うのかもしれません。 また、es2、gl+、pyopeng12についてやってみましたが、それらが無いというエラーになり、事態は後退してしまいました。

そもそも、エラーメッセージも載せて無いなか、コメント頂きありがとうございました。あらためて、エラー出力を載せます。 その前に、python -c "import vispy; print(vispy.sys_info())"の結果は、 Platform: Windows-7-6.1.7601-SP1 Python: 3.7.1 (default, Dec 10 2018, 22:54:23) [MSC v.1915 64 bit (AMD64)] NumPy: 1.15.4 Backend: PyQt5 pyqt4: None pyqt5: ('PyQt5', '5.9.2', '5.9.6') pyside: None pyglet: pyglet 1.3.2 glfw: None sdl2: None wx: None egl: None osmesa: None _test: None

App info-gathering error: Traceback (most recent call last): File "C:\Users\tomo\Anaconda3\lib\site-packages\vispy\util\config.py", line 434, in sys_info out += 'GL version: %r\n' % (gl.glGetParameter(gl.GL_VERSION),) File "C:\Users\tomo\Anaconda3\lib\site-packages\vispy\gloo\gl_gl2.py", line 798, in glGetParameter res = nativefunc(name) File "C:\Users\tomo\Anaconda3\lib\site-packages\pyglet\gl\lib.py", line 105, in errcheck raise GLException(msg) pyglet.gl.lib.GLException: b'invalid operation'

後半に、エラーが出ているようです。

実行時のエラーメッセージは、長いのですが、 C:\Users\tomo\Anaconda3\lib\site-packages\vispy\visuals\isocurve.py:22: UserWarning: VisPy is not yet compatible with matplotlib 2.2+ warnings.warn("VisPy is not yet compatible with matplotlib 2.2+") WARNING: Traceback (most recent call last): File "C:\Users\tomo\Anaconda3\lib\runpy.py", line 193, in _run_module_as_main "main", mod_spec) File "C:\Users\tomo\Anaconda3\lib\runpy.py", line 85, in _run_code exec(code, run_globals) File "C:\Users\tomo\Anaconda3\lib\site-packages\ipykernel_launcher.py", line 16, in app.launch_new_instance() File "C:\Users\tomo\Anaconda3\lib\site-packages\traitlets\config\application.py", line 658, in launch_instance app.start() File "C:\Users\tomo\Anaconda3\lib\site-packages\ipykernel\kernelapp.py", line 505, in start self.io_loop.start() File "C:\Users\tomo\Anaconda3\lib\site-packages\tornado\platform\asyncio.py", line 132, in start self.asyncio_loop.run_forever() File "C:\Users\tomo\Anaconda3\lib\asyncio\base_events.py", line 528, in run_forever self._run_once() File "C:\Users\tomo\Anaconda3\lib\asyncio\base_events.py", line 1764, in _run_once handle._run() File "C:\Users\tomo\Anaconda3\lib\asyncio\events.py", line 88, in _run self._context.run(self._callback, self._args) File "C:\Users\tomo\Anaconda3\lib\site-packages\tornado\ioloop.py", line 758, in _run_callback ret = callback() File "C:\Users\tomo\Anaconda3\lib\site-packages\tornado\stack_context.py", line 300, in null_wrapper return fn(args, kwargs) File "C:\Users\tomo\Anaconda3\lib\site-packages\tornado\gen.py", line 1233, in inner self.run() File "C:\Users\tomo\Anaconda3\lib\site-packages\tornado\gen.py", line 1147, in run yielded = self.gen.send(value) File "C:\Users\tomo\Anaconda3\lib\site-packages\ipykernel\kernelbase.py", line 357, in process_one yield gen.maybe_future(dispatch(args)) File "C:\Users\tomo\Anaconda3\lib\site-packages\tornado\gen.py", line 326, in wrapper yielded = next(result) File "C:\Users\tomo\Anaconda3\lib\site-packages\ipykernel\kernelbase.py", line 267, in dispatch_shell yield gen.maybe_future(handler(stream, idents, msg)) File "C:\Users\tomo\Anaconda3\lib\site-packages\tornado\gen.py", line 326, in wrapper yielded = next(result) File "C:\Users\tomo\Anaconda3\lib\site-packages\ipykernel\kernelbase.py", line 534, in execute_request user_expressions, allow_stdin, File "C:\Users\tomo\Anaconda3\lib\site-packages\tornado\gen.py", line 326, in wrapper yielded = next(result) File "C:\Users\tomo\Anaconda3\lib\site-packages\ipykernel\ipkernel.py", line 294, in do_execute res = shell.run_cell(code, store_history=store_history, silent=silent) File "C:\Users\tomo\Anaconda3\lib\site-packages\ipykernel\zmqshell.py", line 536, in run_cell return super(ZMQInteractiveShell, self).run_cell(args, kwargs) File "C:\Users\tomo\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2819, in run_cell raw_cell, store_history, silent, shell_futures) File "C:\Users\tomo\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2845, in _run_cell return runner(coro) File "C:\Users\tomo\Anaconda3\lib\site-packages\IPython\core\async_helpers.py", line 67, in _pseudo_sync_runner coro.send(None) File "C:\Users\tomo\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 3020, in run_cell_async interactivity=interactivity, compiler=compiler, result=result) File "C:\Users\tomo\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 3185, in run_ast_nodes if (yield from self.run_code(code, result)): File "C:\Users\tomo\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 3267, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "", line 54, in visualizer.update(u) File "..\alifebook_lib\visualizers\matrix_visualizer.py", line 36, in update app.process_events() File "C:\Users\tomo\Anaconda3\lib\site-packages\vispy\app_default_app.py", line 79, in process_events return default_app.process_events() File "C:\Users\tomo\Anaconda3\lib\site-packages\vispy\app\application.py", line 78, in process_events return self._backend._vispy_process_events() File "C:\Users\tomo\Anaconda3\lib\site-packages\vispy\app\backends_qt.py", line 222, in _vispy_process_events app.processEvents() File "C:\Users\tomo\Anaconda3\lib\site-packages\vispy\app\backends_qt.py", line 436, in event out = super(QtBaseCanvasBackend, self).event(ev) File "C:\Users\tomo\Anaconda3\lib\site-packages\vispy\app\backends_qt.py", line 708, in paintGL self._vispy_canvas.events.draw(region=None) File "C:\Users\tomo\Anaconda3\lib\site-packages\vispy\util\event.py", line 455, in call self._invoke_callback(cb, event) File "C:\Users\tomo\Anaconda3\lib\site-packages\vispy\util\event.py", line 475, in _invoke_callback self, cb_event=(cb, event)) << caught exception here: >> File "C:\Users\tomo\Anaconda3\lib\site-packages\vispy\util\event.py", line 471, in _invoke_callback cb(event) File "..\alifebook_lib\visualizers\matrix_visualizer.py", line 28, in _on_draw self._render_program.draw(gloo.gl.GL_TRIANGLE_STRIP) File "C:\Users\tomo\Anaconda3\lib\site-packages\vispy\gloo\program.py", line 470, in draw canvas.context.flush_commands() File "C:\Users\tomo\Anaconda3\lib\site-packages\vispy\gloo\context.py", line 170, in flush_commands self.shared.parser.parse([('CURRENT', 0)]) File "C:\Users\tomo\Anaconda3\lib\site-packages\vispy\gloo\glir.py", line 477, in parse self._parse(command) File "C:\Users\tomo\Anaconda3\lib\site-packages\vispy\gloo\glir.py", line 404, in _parse self._gl_initialize() File "C:\Users\tomo\Anaconda3\lib\site-packages\vispy\gloo\glir.py", line 502, in _gl_initialize if this_version < '2.1': File "C:\Users\tomo\Anaconda3\lib\distutils\version.py", line 52, in lt c = self._cmp(other) File "C:\Users\tomo\Anaconda3\lib\distutils\version.py", line 335, in _cmp if self.version == other.version: AttributeError: 'LooseVersion' object has no attribute 'version' ERROR: Invoking <bound method MatrixVisualizer._on_draw of <alifebook_lib.visualizers.matrix_visualizer.MatrixVisualizer object at 0x0000000004EB0278>> for DrawEvent WARNING: Traceback (most recent call last): File "C:\Users\tomo\Anaconda3\lib\runpy.py", line 193, in _run_module_as_main "main", mod_spec) File "C:\Users\tomo\Anaconda3\lib\runpy.py", line 85, in _run_code exec(code, run_globals) File "C:\Users\tomo\Anaconda3\lib\site-packages\ipykernel_launcher.py", line 16, in app.launch_new_instance() File "C:\Users\tomo\Anaconda3\lib\site-packages\traitlets\config\application.py", line 658, in launch_instance app.start() File "C:\Users\tomo\Anaconda3\lib\site-packages\ipykernel\kernelapp.py", line 505, in start self.io_loop.start() File "C:\Users\tomo\Anaconda3\lib\site-packages\tornado\platform\asyncio.py", line 132, in start self.asyncio_loop.run_forever() File "C:\Users\tomo\Anaconda3\lib\asyncio\base_events.py", line 528, in run_forever self._run_once() File "C:\Users\tomo\Anaconda3\lib\asyncio\base_events.py", line 1764, in _run_once handle._run() File "C:\Users\tomo\Anaconda3\lib\asyncio\events.py", line 88, in _run self._context.run(self._callback, self._args) File "C:\Users\tomo\Anaconda3\lib\site-packages\tornado\ioloop.py", line 758, in _run_callback ret = callback() File "C:\Users\tomo\Anaconda3\lib\site-packages\tornado\stack_context.py", line 300, in null_wrapper return fn(args, kwargs) File "C:\Users\tomo\Anaconda3\lib\site-packages\tornado\gen.py", line 1233, in inner self.run() File "C:\Users\tomo\Anaconda3\lib\site-packages\tornado\gen.py", line 1147, in run yielded = self.gen.send(value) File "C:\Users\tomo\Anaconda3\lib\site-packages\ipykernel\kernelbase.py", line 357, in process_one yield gen.maybe_future(dispatch(args)) File "C:\Users\tomo\Anaconda3\lib\site-packages\tornado\gen.py", line 326, in wrapper yielded = next(result) File "C:\Users\tomo\Anaconda3\lib\site-packages\ipykernel\kernelbase.py", line 267, in dispatch_shell yield gen.maybe_future(handler(stream, idents, msg)) File "C:\Users\tomo\Anaconda3\lib\site-packages\tornado\gen.py", line 326, in wrapper yielded = next(result) File "C:\Users\tomo\Anaconda3\lib\site-packages\ipykernel\kernelbase.py", line 534, in execute_request user_expressions, allow_stdin, File "C:\Users\tomo\Anaconda3\lib\site-packages\tornado\gen.py", line 326, in wrapper yielded = next(result) File "C:\Users\tomo\Anaconda3\lib\site-packages\ipykernel\ipkernel.py", line 294, in do_execute res = shell.run_cell(code, store_history=store_history, silent=silent) File "C:\Users\tomo\Anaconda3\lib\site-packages\ipykernel\zmqshell.py", line 536, in run_cell return super(ZMQInteractiveShell, self).run_cell(args, kwargs) File "C:\Users\tomo\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2819, in run_cell raw_cell, store_history, silent, shell_futures) File "C:\Users\tomo\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2845, in _run_cell return runner(coro) File "C:\Users\tomo\Anaconda3\lib\site-packages\IPython\core\async_helpers.py", line 67, in _pseudo_sync_runner coro.send(None) File "C:\Users\tomo\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 3020, in run_cell_async interactivity=interactivity, compiler=compiler, result=result) File "C:\Users\tomo\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 3185, in run_ast_nodes if (yield from self.run_code(code, result)): File "C:\Users\tomo\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 3267, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "", line 54, in visualizer.update(u) File "..\alifebook_lib\visualizers\matrix_visualizer.py", line 36, in update app.process_events() File "C:\Users\tomo\Anaconda3\lib\site-packages\vispy\app_default_app.py", line 79, in process_events return default_app.process_events() File "C:\Users\tomo\Anaconda3\lib\site-packages\vispy\app\application.py", line 78, in process_events return self._backend._vispy_process_events() File "C:\Users\tomo\Anaconda3\lib\site-packages\vispy\app\backends_qt.py", line 222, in _vispy_process_events app.processEvents() File "C:\Users\tomo\Anaconda3\lib\site-packages\vispy\app\backends_qt.py", line 436, in event out = super(QtBaseCanvasBackend, self).event(ev) File "C:\Users\tomo\Anaconda3\lib\site-packages\vispy\app\backends_qt.py", line 708, in paintGL self._vispy_canvas.events.draw(region=None) File "C:\Users\tomo\Anaconda3\lib\site-packages\vispy\util\event.py", line 455, in call self._invoke_callback(cb, event) File "C:\Users\tomo\Anaconda3\lib\site-packages\vispy\util\event.py", line 475, in _invoke_callback self, cb_event=(cb, event)) << caught exception here: >> File "C:\Users\tomo\Anaconda3\lib\site-packages\vispy\gloo\gl_gl2.py", line 269, in glCreateProgram nativefunc = glCreateProgram._native AttributeError: 'function' object has no attribute '_native'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Users\tomo\Anaconda3\lib\site-packages\vispy\gloo\gl\gl2.py", line 72, in _get_gl_func func = getattr(_lib, name) File "C:\Users\tomo\Anaconda3\lib\ctypes__init.py", line 369, in getattr func = self.getitem(name) File "C:\Users\tomo\Anaconda3\lib\ctypes\init.py", line 374, in getitem__ func = self._FuncPtr((name_or_ordinal, self)) AttributeError: function 'glCreateProgram' not found

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Users\tomo\Anaconda3\lib\site-packages\vispy\util\event.py", line 471, in _invoke_callback cb(event) File "C:\Users\tomo\Anaconda3\lib\site-packages\vispy\gloo\context.py", line 171, in flush_commands self.glir.flush(self.shared.parser) File "C:\Users\tomo\Anaconda3\lib\site-packages\vispy\gloo\glir.py", line 232, in flush self._shared.flush(parser) File "C:\Users\tomo\Anaconda3\lib\site-packages\vispy\gloo\glir.py", line 146, in flush parser.parse(self._filter(self.clear(), parser)) File "C:\Users\tomo\Anaconda3\lib\site-packages\vispy\gloo\glir.py", line 477, in parse self._parse(command) File "C:\Users\tomo\Anaconda3\lib\site-packages\vispy\gloo\glir.py", line 417, in _parse self.objects[id] = klass(self, id_) File "C:\Users\tomo\Anaconda3\lib\site-packages\vispy\gloo\glir.py", line 546, in init self.create() File "C:\Users\tomo\Anaconda3\lib\site-packages\vispy\gloo\glir.py", line 600, in create self._handle = gl.glCreateProgram() File "C:\Users\tomo\Anaconda3\lib\site-packages\vispy\gloo\gl_gl2.py", line 271, in glCreateProgram nativefunc = glCreateProgram._native = _get_gl_func("glCreateProgram", ctypes.c_uint, ()) File "C:\Users\tomo\Anaconda3\lib\site-packages\vispy\gloo\gl\gl2.py", line 87, in _get_gl_func raise RuntimeError('Using %s with no OpenGL context.' % name) RuntimeError: Using glCreateProgram with no OpenGL context. ERROR: Invoking <bound method GLContext.flush_commands of <GLContext at 0x8492668>> for DrawEvent ERROR: Invoking <bound method MatrixVisualizer._on_draw of <alifebook_lib.visualizers.matrix_visualizer.MatrixVisualizer object at 0x0000000004EB0278>> repeat 2 ERROR: Invoking <bound method GLContext.flush_commands of <GLContext at 0x8492668>> repeat 2 ERROR: Invoking <bound method MatrixVisualizer._on_draw of <alifebook_lib.visualizers.matrix_visualizer.MatrixVisualizer object at 0x0000000004EB0278>> repeat 4 ERROR: Invoking <bound method GLContext.flush_commands of <GLContext at 0x8492668>> repeat 4 ERROR: Invoking <bound method MatrixVisualizer._on_draw of <alifebook_lib.visualizers.matrix_visualizer.MatrixVisualizer object at 0x0000000004EB0278>> repeat 8 ERROR: Invoking <bound method GLContext.flush_commands of <GLContext at 0x8492668>> repeat 8 ERROR: Invoking <bound method MatrixVisualizer._on_draw of <alifebook_lib.visualizers.matrix_visualizer.MatrixVisualizer object at 0x0000000004EB0278>> repeat 16 ERROR: Invoking <bound method GLContext.flush_commands of <GLContext at 0x8492668>> repeat 16 ERROR: Invoking <bound method MatrixVisualizer._on_draw of <alifebook_lib.visualizers.matrix_visualizer.MatrixVisualizer object at 0x0000000004EB0278>> repeat 32 ERROR: Invoking <bound method GLContext.flush_commands of <GLContext at 0x8492668>> repeat 32 ERROR: Invoking <bound method MatrixVisualizer._on_draw of <alifebook_lib.visualizers.matrix_visualizer.MatrixVisualizer object at 0x0000000004EB0278>> repeat 64 ERROR: Invoking <bound method GLContext.flush_commands of <GLContext at 0x8492668>> repeat 64 ERROR: Invoking <bound method MatrixVisualizer._on_draw of <alifebook_lib.visualizers.matrix_visualizer.MatrixVisualizer object at 0x0000000004EB0278>> repeat 128 ERROR: Invoking <bound method GLContext.flush_commands of <GLContext at 0x8492668>> repeat 128 ERROR: Invoking <bound method MatrixVisualizer._on_draw of <alifebook_lib.visualizers.matrix_visualizer.MatrixVisualizer object at 0x0000000004EB0278>> repeat 256 ERROR: Invoking <bound method GLContext.flush_commands of <GLContext at 0x8492668>> repeat 256

mitsuyoshi-yamazaki commented 5 years ago

OpenGLのバージョン2未満では glCreateProgram を利用できないため上記のエラーが出ているかもしれません。 グラフィックカードのドライバを更新してみたらどうなるでしょうか。

https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glCreateProgram.xhtml

mitsuyoshi-yamazaki commented 5 years ago

一応描画系を書き換えればweb上でも動かせられました

https://github.com/alifelab/alife_book_src/issues/28#issuecomment-470482439

tomotomo47 commented 5 years ago

OpenGLのバージョンは3.1でした。一応、更新して再起動とかをしてみます。

tomotomo47 commented 5 years ago

アナコンダを再インストールしても駄目で、原始的ですが、自分でuを直接256×256のbmpファイルにして、aviファイルへ結合という手段で、動作自体は確認できました。

test0 test20 test40 test60 test80

StatsBeginner commented 1 year ago

答えになってなくて恐縮ですが、同じくgray_scott.pyが動かず、他のプログラムも動かないといいますか、中が透けたウィンドウ枠が出るだけです。windows7です。どなたか解決された方はいらっしゃらないでしょうか?

Mac OS (Ventura 13.2.1) Python 3.8.3 Vispy 0.12.2 pyqt5 5.15.9

という環境でやってみていますが(出版から時間が経っているのでvispyのバージョンはだいぶ違います)、同じようにgray_scott.pyは描画デバイスだけひらいて何も描画されないです。 ただ、2章のセルラーオートマトンや、3章以降の他のサンプルコードはちゃんとアニメーション表示されたので(gray_scott_param.pyはダメ)、vispyとかpyqtとかOpenGLの問題とは違うのかも知れません。

Tetsuro-Ishida commented 11 months ago

答えになってなくて恐縮ですが、同じくgray_scott.pyが動かず、他のプログラムも動かないといいますか、中が透けたウィンドウ枠が出るだけです。windows7です。どなたか解決された方はいらっしゃらないでしょうか?

Mac OS (Ventura 13.2.1) Python 3.8.3 Vispy 0.12.2 pyqt5 5.15.9

という環境でやってみていますが(出版から時間が経っているのでvispyのバージョンはだいぶ違います)、同じようにgray_scott.pyは描画デバイスだけひらいて何も描画されないです。 ただ、2章のセルラーオートマトンや、3章以降の他のサンプルコードはちゃんとアニメーション表示されたので(gray_scott_param.pyはダメ)、vispyとかpyqtとかOpenGLの問題とは違うのかも知れません。

こちらですが、おそらく似た環境(Mac OS Monterey 12.5.1、Python 3.9.5、Vispy 0.14.0, PyQt5 5.15.9)で、matrix_visualizer.pyのMatrixVisualizerクラスの初期化部分の最終2行を以下のコードに書き換えれば問題なく動作しました。

gloo.set_viewport(0, 0, *self._canvas.physical_size)
gloo.set_clear_color('white')
self._canvas.show()