2

运行以下行后(已经存在包):

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'


我执行以下操作:

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

我收到以下错误:

---------------------------------------------------------------------------
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'

我正在使用 python 3.6 和 pip。我正在使用标志 -vvv 来更详细地帮助调试错误。

4

1 回答 1

1

pystan.py周围有一个文件。import pystan从文件而不是已安装的pystan包导入。

删除或重命名文件。并且永远不要创建.py隐藏现有模块的文件,如email.py,test.py等。

于 2020-05-06T16:46:13.457 回答