安装streamlit等依赖时遇ModuleNotFoundError的解决方法
安装streamlit、fbprophet等依赖失败的解决办法
问题背景
要安装依赖:streamlit、fbprophet、yfinance、plotly,执行命令:
pip install streamlit fbprophet yfinance plotly
终端出现如下错误:
Collecting streamlit Using cached streamlit-1.14.0-py2.py3-none-any.whl (9.2 MB) Collecting fbprophet Using cached fbprophet-0.7.1.tar.gz (64 kB) Preparing metadata (setup.py) ... done Collecting yfinance Using cached yfinance-0.1.85-py2.py3-none-any.whl (29 kB) Collecting plotly Using cached plotly-5.11.0-py2.py3-none-any.whl (15.3 MB) # 省略中间依赖收集内容 Collecting pystan>=2.14 Using cached pystan-3.5.0-py3-none-any.whl (13 kB) Using cached pystan-3.4.0-py3-none-any.whl (13 kB) Using cached pystan-3.3.0-py3-none-any.whl (13 kB) Using cached pystan-3.1.1-py3-none-any.whl (13 kB) ╰─> [6 lines of output] Traceback (most recent call last): File "<string>", line 2, in <module> File "<pip-setuptools-caller>", line 34, in <module> File "C:\Users\Admin\AppData\Local\Temp\pip-install-cpz50fug\pystan_29b2e0ee589444e48d57493b846dbeee\setup.py", line 122, in <module> from Cython.Build.Inline import _get_build_extension ModuleNotFoundError: No module named 'Cython' [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. error: metadata-generation-failed × Encountered error while generating package metadata. ╰─> See above for output. note: This is an issue with the package mentioned above, not pip. hint: See above for details.
核心问题
- 缺少
Cython依赖,pystan编译过程必须依赖它; - fbprophet 0.7.1仅兼容pystan 2.x版本,但pip默认拉取了不兼容的pystan 3.x版本。
解决步骤
方法一:使用pip安装(通用场景)
- 先单独安装Cython
pip install cython
- 安装与fbprophet兼容的pystan版本
pip install pystan==2.19.1.1
- 再安装所有目标依赖
pip install streamlit yfinance plotly fbprophet
方法二:Anaconda环境推荐方案(更稳定)
Anaconda能自动处理大部分编译依赖问题,优先使用conda命令:
- 激活你的目标conda环境
conda activate your_env_name
- 安装Cython和兼容版pystan
conda install -c conda-forge cython pystan=2.19.1.1
- 一次性安装所有目标依赖
conda install -c conda-forge streamlit fbprophet yfinance plotly
额外注意事项
- 如果仍有其他错误,先更新pip到最新版本:
pip install --upgrade pip - 确保你的Python版本在3.7-3.9之间(fbprophet 0.7.1对Python 3.10+支持有限)
内容的提问来源于stack exchange,提问作者Mr.Horror
相关产品推荐
相关产品推荐

