Frustrating problems with Pystan (anaconda Python)

I have the same issue. I have macOS 11.6 and ran the following command:

conda create -n stan_env -c conda-forge python=3.9 numpy cython pandas matplotlib scipy pystan jupyter notebook

Once installed, I needed to add these commands at the top of my jupyter notebook (in order to avoid the error RuntimeError: cannot be called from a running event loop):

import nest_asyncio
del nest_asyncio

Finally, running the quick start code from the doc (PyStan — pystan 3.3.0 documentation), I get the same error:

FileNotFoundError: [Errno 2] No such file or directory: '/Users/myuser/opt/miniconda3/envs/stan_env/lib/python3.9/site-packages/httpstan/stanc'

and at the bottom of the error stream:

ValueError: The JSON document has an improper structure: missing or superfluous commas, braces, missing keys, etc.

I tried a bunch of different variations of the conda install but nothing works.

As PyStan 3 does not publish conda packages, conda isn’t officially supported. Using a normal virtualenv should work fine for you on macOS 11.6.

If someone has had success using conda with PyStan 3, perhaps they could post a quick tutorial (as a separate post) describing the required steps.

1 Like

Perhaps some of these "how do i even install the dependencies to run the software as a new user on platform x using package managers y and z " problems could be avoided by distributing a self-contained and tested Stan container image with pinned versions of dependencies (compilers, libraries, etc) atop a supported base image (e.g. debian stable).

I see earlier this year @wm1995 shared an example Dockerfile that installs pystan3 atop a python:latest image, which appears to be based on debian 11 bullseye, which is one of the operating systems supported by pystan:

With a container image there would still be a bit of a learning barrier for new users unfamiliar with wrangling container images: e.g. how do i run a container image locally (in this case installing docker for mac or perhaps an alternative like podman), how do i configure volume mounts and port forwarding to be able to share data and source code with a container or view a notebook hosted in the container – but there would no longer be any opportunity for users to accidentally pick combinations of build environments and package managers that aren’t supported or don’t work.


I’m cautiously optimistic that all these problems will disappear over the next 24 months as people stop using Linux distributions published before 2019.

I just want to echo the above, I’ve tried pip install pystan from two different virtual environments (virtualenv and pipenv) on MacOs 10.14 with two different versions of Python (3.8.8 and 3.9.5) and in every case, with two different pip versions (20.2.3 and 21.3), none of them are able to install pystan 3.x, every time it falls back to 2.19.

This should not happen on intel macOS machines. (M1 is not supported right now.) Can you describe your environment in greater detail?

(That said, if you’re not using anaconda, you might want to create a new post as this one concerns Anaconda.)

Hi, I hope you are well - do you have an idea when pystan 3 could be available for the M1 Macs?

Thank you so much for all the work on it

1 Like

Hi @Replicant_Rin - there was recently this post here:


Hi @WardBrian

Thank you so much! Had to create a new virtual env but it did work (after failing twice lol) !

1 Like