2

After running the following line (already exist the package):

pip install -vvv pystan

Requirement already satisfied: pystan in /Users/cmougan/anaconda3/lib/python3.6/site-packages (2.17.1.0)
Requirement already satisfied: Cython!=0.25.1,>=0.22 in /Users/cmougan/anaconda3/lib/python3.6/site-packages (from pystan) (0.28.2)
Requirement already satisfied: numpy>=1.7 in /Users/cmougan/anaconda3/lib/python3.6/site-packages (from pystan) (1.16.2)
Carloss-MacBook-Pro:Desktop cmougan$ pip install -vvv pystan
Non-user install because site-packages writeable
Created temporary directory: /private/var/folders/j6/tcx3t7vj4fs8rsb97cwg06nc0000gn/T/pip-ephem-wheel-cache-0p2f3viv
Created temporary directory: /private/var/folders/j6/tcx3t7vj4fs8rsb97cwg06nc0000gn/T/pip-req-tracker-lg301zxr
Initialized build tracking at /private/var/folders/j6/tcx3t7vj4fs8rsb97cwg06nc0000gn/T/pip-req-tracker-lg301zxr
Created build tracker: /private/var/folders/j6/tcx3t7vj4fs8rsb97cwg06nc0000gn/T/pip-req-tracker-lg301zxr
Entered build tracker: /private/var/folders/j6/tcx3t7vj4fs8rsb97cwg06nc0000gn/T/pip-req-tracker-lg301zxr
Created temporary directory: /private/var/folders/j6/tcx3t7vj4fs8rsb97cwg06nc0000gn/T/pip-install-8ffjd5t4
Requirement already satisfied: pystan in /Users/cmougan/anaconda3/lib/python3.6/site-packages (2.17.1.0)
Requirement already satisfied: Cython!=0.25.1,>=0.22 in /Users/cmougan/anaconda3/lib/python3.6/site-packages (from pystan) (0.28.2)
Requirement already satisfied: numpy>=1.7 in /Users/cmougan/anaconda3/lib/python3.6/site-packages (from pystan) (1.16.2)
Removed build tracker: '/private/var/folders/j6/tcx3t7vj4fs8rsb97cwg06nc0000gn/T/pip-req-tracker-lg301zxr'


I perform the following:

import pystan
model_code = 'parameters {real y;} model {y ~ normal(0,1);}'
model = pystan.StanModel(model_code=model_code)  # this will take a minute
y = model.sampling(n_jobs=1).extract()['y']
y.mean()  # should be close to 0

And I get the following error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-40-d7f147a8ee3e> in <module>
      1 import pystan
      2 model_code = 'parameters {real y;} model {y ~ normal(0,1);}'
----> 3 model = pystan.StanModel(model_code=model_code)  # this will take a minute
      4 y = model.sampling(n_jobs=1).extract()['y']
      5 y.mean()  # should be close to 0

AttributeError: module 'pystan' has no attribute 'StanModel'

I am using python 3.6 and pip. I am using the flag -vvv for more verbose to help in the debugging of the error.

Carlos Mougan
  • 761
  • 1
  • 8
  • 21

1 Answers1

1

You have a file pystan.py lying around. import pystan imports from the file instead of the installed pystan package.

Remove or rename the file. And never create files .py that shadows existing modules like email.py, test.py, etc.

phd
  • 82,685
  • 13
  • 120
  • 165