Getting started with pystan - install and setup (macOS M1)

Hello, I am reaching out to get help with getting pystan to work properly on my Mac. I have tried dozens of installs for pystan, CmdStan and many versions of python but for some reason I can never get it to work properly. I am relatively new to programming in languages outside of python so I would appreciate any help I can get.
I am using an M1 Mac with Ventura, I would like to code in PyCharm or Jupyter notebook. Throughout my effort to get Stan working, I have followed the install guides to download Stan, but any time I attempt to run the starter code in my terminal I get hit with error messages stating that Stan is not installed. I have resorted to importing Stan into pycharm (I added a picture with this post). As shown in the image, I just get “INFO:pystan:COMPILING THE C++ CODE FOR MODEL anon_model_67cb7d0f2cb7720776cbeb52007d2dbb NOW.” popping up many times follows by some errors. Following the errors, the compile messages show up and there is an infinite loop. No matter where I try to run this code, the result is the same. I have run out of options. I have python 3.10.5, and I think my pystan version is 3

If anyone has any comments, I would really appreciate it. I am open to completely restarting this entire process in a new IDE if needed, but I have no clue what to do from here.

I would be more than happy to provide any additional information.

Thanks in advance!

@ariddell might be able to help. Or you can open an issue against PyStan.

Most of our dev effort has moved to cmdstanpy, and I’d suggest trying that, as it’s much easier to install (it connects to CmdStan in a separate process and thus doesn’t need binary compatibility with Python). Then if you need to access gradients and function values, there’s BridgeStan.

Thank you for your reply, I appreciate it.

I have reached out to ariddell per your recommendation.

If possible, would you be able to assist or refer me to getting started with cmdstanpy? I have also attempted to use this but it hasn’t been working for me either.

Thank you in advance.

Installing on Apple Silicon takes a little bit of extra work. Check out this FAQ entry: Frequently Asked Questions — pystan 3.7.0 documentation

1 Like

Thank you for the reply!

Hey Bob, I think I know the answer, but just to be sure. I managed to get my code working using cmdstan, but pystan never compiles on my MacBook Pro (M1 2021). I am assuming it is better to stick to cmdstan?

Many thanks …

instead of PyStan, I recommend CmdStanPy. I just installed it on my M3 MacBook Air.
I had to install via pip, because the conda-forge install didn’t work for me (problems with the tbb lib)

@mitzimorris - thank you!

Think I need to ensure that PyStan is removed (so no clash with CmdStanPy). Plus, it seems like it needs to be installed in a new/ its own environment, and I need to be in that environment to run things.

BTW - did you have do anything different in Jupyter Notebooks, is you use them?

I don’t know if there are any environment clashes between PyStan and CmdStanPy.

there are a bunch of example notebooks here: CmdStanPy Examples — CmdStanPy 1.2.2 documentation

also an extended case study here:

Super helpful. Thank you very much…

1 Like