Just thought I’d give a post on some issues that I had setting up PyStan 3, and how I got around them, in case there’s someone else this might help.
I tried to get PyStan 3 set up to run in a Docker container, but was getting C++ compiler error messages about an undefined symbol nested in a lengthy Python error traceback when executing the
stan.build() method. The reason for this seems to be a dependency on gcc ≥9.0 (or clang ≥10.0) - this is now stated in the documentation to the
httpstan module, a dependency of PyStan 3. The
python:latest Docker Hub image (at time of writing) uses Debian Buster with gcc version 8.3.0; updating this to the latest gcc resolved the issue for me. I’ve included an example of the error messages that I was receiving with the out-of-date gcc compiler, and an example Dockerfile that sets up a working PyStan 3 container.
I was doing this specifically within a Docker container, but I suspect the error will arise for anyone using an out-of-date compiler. The only change I needed was to update to a newer gcc version, and the PyPI wheels worked fine after that.
Example error message
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.0/models/ekul4lrl/stan_services_model_ekul4lrl.cpython-39-x86_64-linux-gnu.so: undefined symbol: _ZNSt19basic_ostringstreamIcSt11char_traitsIcESaIcEEC1Ev Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python3.9/site-packages/stan/model.py", line 426, 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 415, 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.
Example Dockerfile for a functional PyStan 3 container
FROM python:latest # Need to install the updated gcc compiler for Pystan 3 # Add the Debian source list RUN echo 'deb http://deb.debian.org/debian testing main' >> /etc/apt/sources.list # Update the repos RUN apt-get update -y # Install the latest gcc (should be version 10) RUN apt-get install -y gcc # No need to install further packages so remove the lists to save space RUN rm -rf /var/lib/apt/lists/* # Install PyStan RUN pip install --pre pystan
Hope this helps anyone else who may have a similar issue.