fbprophet 库是Google开发的一个用于时间序列分析的库,该库的运行需要用到 C++ 编译,因此最开始使用 python 安装的时候会出现很多问题。本文总结了整个安装过程,记录在此。
首先,先阐述初始配置情况:我习惯使用在 Anaconda 上使用 Spyder 来写代码,win10 系统,系统基础的环境是 python3.11。
但是 fbprophet 只支持 py2.7、3.5~3.8,因此需要配置一个新的虚拟环境来安装fbprophet. 当时给我的报错如下,读者可自行参考:
Channels:
- conda-forge
- defaults
- msys2
Platform: win-64
Collecting package metadata (repodata.json): done
Solving environment: / warning libmamba Added empty dependency for problem type SOLVER_RULE_UPDATE
failed
LibMambaUnsatisfiableError: Encountered problems while solving:
- package fbprophet-0.2-py27_vc9_0 requires python 2.7*, but none of the providers can be installed
Could not solve for environment specs
The following packages are incompatible
├─ fbprophet is installable with the potential options
│ ├─ fbprophet [0.1.1|0.2|0.2.1|0.3.post2] would require
│ │ └─ python [3.5* |>=3.5,<3.6.0a0 ], which can be installed;
│ ├─ fbprophet [0.1.1|0.2|0.2.1] would require
│ │ └─ python 3.6* , which can be installed;
│ ├─ fbprophet [0.2|0.2.1|0.3.post2] would require
│ │ └─ python [2.7* |>=2.7,<2.8.0a0 ], which can be installed;
│ ├─ fbprophet [0.3.post2|0.4.post2|0.5|0.6|0.7.1] would require
│ │ └─ python >=3.6,<3.7.0a0 , which can be installed;
│ ├─ fbprophet [0.5|0.6|0.7.1] would require
│ │ └─ python >=3.7,<3.8.0a0 , which can be installed;
│ └─ fbprophet 0.7.1 would require
│ └─ python >=3.8,<3.9.0a0 , which can be installed;
└─ pin-1 is not installable because it requires
└─ python 3.9.* , which conflicts with any installable versions previously reported.
具体步骤参考【博客】。创建完后激活这个环境。我配置的是 python 3.7 的环境,因为最新的 Anaconda 在配置 python 3.6 版本后,对应的 Spyder 无法加载出来。
激活环境后,在环境下输入以下代码:
conda install spyder
即可安装。安装完成后,会出现一个命名为 “Spyder(环境名)” 的新Spyder。
在 Anaconda Prompt 中,根据该【博客】安装 fbprophet 库。切记,千万不能使用pip直接安装。
具体步骤如下:
# 管理员打开ananconda prompt
# 1.安装MingW-w64编译器类型:
conda install libpython m2w64-toolchain -c msys2
# 检查你的虚拟环境路径下\Lib\distutils中是否有distutils.cfg文件,如果没有就手动创建一个
# 2.
conda install numpy cython -c conda-forge
# 3.
conda install matplotlib scipy pandas -c conda-forge
# 4.
conda install pystan -c conda-forge
# 5.
conda install fbprophet -c conda-forge
在 import fbprophet 时,可能会出现以下报错:
TypeError: This is a python-holidays entity loader class. For entity inheritance purposes please import a class you want to derive from directly: e.g.,
from holidays.countries import Entity
orfrom holidays.financial import Entity
.
根据错误信息看起来,fbprophet 中的某个模块尝试导入 holidays 模块时出现了问题。这可能是由于 holidays 模块的版本问题或者在导入过程中发生了一些错误。此时需要更新 holidays 模块,我采取以下方式更新 holidays:
pip install --upgrade --index-url https://pypi.tuna.tsinghua.edu.cn/simple/ holidays==0.11.1
这是清华源的pip安装模块,切记断开,不然网络连接不上。
接着在更新holidays过程中,会出现以下报错:
ERROR: pip’s dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
fbprophet 0.7.1 requires cmdstanpy==0.9.5, which is not installed.
fbprophet 0.7.1 requires setuptools-git>=1.2, which is not installed.
Successfully installed hijri-converter-2.3.1 holidays-0.11.1 korean-lunar-calendar-0.3.1
holidays 版本 0.11.1 已成功安装。同时,注意到安装过程中有一些依赖冲突,特别是 fbprophet 的依赖未满足。你可能需要安装 cmdstanpy 和 setuptools-git 这两个包,以满足 fbprophet 的要求。具体如下:
conda install -c conda-forge cmdstanpy setuptools-git