New to Pystan, Always get this error when attempting to sample: ModuleNotFoundError: No module named 'stanfit4anon_model...'

I am new to Pystan, and have been having incredible trouble getting simple models to sample.

I receive the error: ModuleNotFoundError: No module named ‘stanfit4anon_model…’

And then my Jupyter Notebook cell runs in perpetuity, until I restart the kernel.

Any advice helps! Thank you.

Hi, what OS do you have?

What does gcc --version say?
What Python and PyStan versions do you use?

Are you able to compile models?

Does sampling work with n_jobs=1

Thank you so much!

OS: Mac 10.15.4

gcc version:

Python version:
image

Is it conflicting that it says Clang 10.0.0 here? And Clang 12.0 in the gcc version?

Pystan version: 2.19.1.1

Able to compile models? - Yes!

Sampling with n_jobs = 1 – this worked! Thank you

What would be the best way to ensure I can run multiple chains at once?

Hi can you try this

import multiprocessing
multiprocessing.set_start_method("fork")
3 Likes

This worked!

Thank you.

This works! Thanks~

It worked!! Make sure to restart the notebook and then run:
import multiprocessing
multiprocessing.set_start_method(“fork”)

before running other commands.
Thank you!!!

I’m having the same problem as the OP, but my context is loading a pickled Stan model from S3 (that was fitted in another notebook). Restarting the notebook and importing multiprocessing does not fix the issue.

I’m using PyStan 2.19 in a Databricks notebook. I can fit the model just fine (using my_stan_model.sampling()) and pickle it to save in S3. But when I try to load the pickled model in a second notebook, I get the No module named 'stanfit4anon_model... error.

I’m able to load a pickled compiled model (from pystan.StanModel) just fine, so the problem seems to be with the fitted model in particular.

In PyStan 2 you also need to save (and then load first) the model object with your fit.

So next time save a list

[model, fit]

If you don’t have the model object saved anymore, you could try the following “hack”

https://pystan2.readthedocs.io/en/latest/unpickling_fit_without_model.html

1 Like

Thanks, that solved it!