pythonanacondaspyderstanpystan

Code works line-by-line in Spyder, but not when the whole script is run


I've installed pystan and am trying to verify that the installation has worked correctly.

When I go to the IPython console in Spyder and run the following code line by line, it generates the correct answer.

import pystan

model_code = 'parameters {real y;} model {y ~ normal(0,1);}'
model = pystan.StanModel(model_code=model_code)
y = model.sampling().extract()['y']
y.mean()

The line calling pystan.StanModel takes about 30 seconds, while the other lines execute instantaneously. In the end I get the right result (about 0, e.g. 0.01 or -0.01).

However, when I run the code as a single script in Spyder, it doesn't work, and instead the console just runs forever, doesn't produce a result, and I have to manually shut down Anaconda. Why is that?


Solution

    1. Run Spyder as administrator
    2. Check your antivirus to make sure whether it is blocking your code
    3. Reset Spyder:

    spyder --reset

    spyder --defaults