首页 > 解决方案 > ImportError:在 MacOS 上没有名为“pystan”的模块

问题描述

pystan使用pip install pystan. 我检查了模块是否与 pip freeze 一起列出。但是当我使用import pystan. 它给出了找不到模块的错误。

下面是 pip freeze 命令的输出。它显示 pystan 版本 3.3.0

aiohttp==3.7.4.post0
appdirs==1.4.4
async-timeout==3.0.1
attrs==21.2.0
chardet==4.0.0
clikit==0.6.2
crashtest==0.3.1
httpstan==4.6.0
idna==3.2
lz4==3.1.3
marshmallow==3.13.0
multidict==5.2.0
numpy==1.21.2
pandas==1.3.3
pastel==0.2.1
pylev==1.4.0
pysimdjson==3.2.0
pystan==3.3.0
python-dateutil==2.8.2
pytz==2021.3
six==1.16.0
typing-extensions==3.10.0.2
webargs==8.0.1
yarl==1.7.0

但是,当我尝试从控制台导入模块时,它会引发以下错误。

import pystan
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
ModuleNotFoundError: No module named 'pystan'

导入列出的任何其他模块不会引发错误。

标签: python-modulepystan

解决方案


我在这个链接上找到了解决方案

显然,最新版本的 pystan (>= 3) 在 import 语句中使用 stan 而不是 pystan,而在早期版本中它只是 pystan。

如果你安装 pystan (>=3) 使用import stan而不是import pystan


推荐阅读