変なつまり方をしたのでメモ
まとめ
- dockerの
python:3.9
をベースイメージに環境を作ろうとしていたが、動かなくて困っていた - pystan 3.0 は gcc ≥ 9.0 が必要であるにも関わらず、python:3.9のイメージに入っているgccはver.8系だったのが原因と思われる
- ubuntu:20.04をベースにしたら治った
症状
ドキュメントのQuick Startにあるコードを実行しようとしていたが、次のようなエラーが起こっていた
Building... This may take some time. Messages from stanc: Warning: The parameter mu has no priors. Warning: The parameter tau has no priors. Error handling request Traceback (most recent call last): File "/usr/local/lib/python3.9/site-packages/aiohttp/web_protocol.py", line 422, in _handle_request resp = await self._request_handler(request) File "/usr/local/lib/python3.9/site-packages/aiohttp/web_app.py", line 499, in _handle resp = await handler(request) File "/usr/local/lib/python3.9/site-packages/httpstan/views.py", line 253, in handle_show_params services_module = httpstan.models.import_services_extension_module(model_name) File "/usr/local/lib/python3.9/site-packages/httpstan/models.py", line 90, in import_services_extension_module module: ModuleType = importlib.util.module_from_spec(spec) # type: ignore File "<frozen importlib._bootstrap>", line 565, in module_from_spec File "<frozen importlib._bootstrap_external>", line 1108, in create_module File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed ImportError: /root/.cache/httpstan/4.4.2/models/dnt4r2yw/stan_services_model_dnt4r2yw.cpython-39-x86_64-linux-gnu.so: undefined symbol: _ZNSt19basic_ostringstreamIcSt11char_traitsIcESaIcEEC1Ev Traceback (most recent call last): File "/src/getting-started.py", line 27, in <module> posterior = stan.build(schools_code, data=schools_data, random_seed=1) File "/usr/local/lib/python3.9/site-packages/stan/model.py", line 450, in build return asyncio.run(go()) File "/usr/local/lib/python3.9/asyncio/runners.py", line 44, in run return loop.run_until_complete(main) File "/usr/local/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete return future.result() File "/usr/local/lib/python3.9/site-packages/stan/model.py", line 439, in go raise RuntimeError(resp.json()["message"]) File "/usr/local/lib/python3.9/site-packages/stan/common.py", line 24, in json return simdjson.loads(self.content) File "/usr/local/lib/python3.9/site-packages/simdjson/__init__.py", line 61, in loads return parser.parse(s, True) ValueError: The JSON document has an improper structure: missing or superfluous commas, braces, missing keys, etc.
原因
おそらく、python:3.9のイメージに入っているgccが古すぎた
# gcc --version gcc (Debian 8.3.0-6) 8.3.0 Copyright (C) 2018 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
apt-get updateして新しいgccを入れようとしても「これが最新」と言われてしまい、このイメージでなんとかしようとするのは手間がかかりそうだった
対処
もっと新しいgccが入ったものを使うことにした
例えばubuntu 20.04はgcc 9.3.0がデフォルトで入っているのでこれを使うことにした
# gcc --version gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0 Copyright (C) 2019 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
これにより問題なくpystanが動くようになった