Facebook的开源时序分析库fbprophet号称史上最难安装的库,实测确实如此。
百度了各种简单粗暴或者详细的安装步骤,期间遭遇了各种各样奇怪的问题,现简录如下:
1.已经安装了pystan的前提下,用conda install -c conda-forge install fbprophet,
(base) C:\WINDOWS\system32>conda install -c conda-forge fbprophet
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.
Collecting package metadata (repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
2.出现上述问题,我尝试了用管理员权限conda update --all, 等所有的包都更新完毕之后,再次conda install -c conda-forge install fbprophet , 读出另一个环境不匹配的问题,我的python版本是3.9,与fbprophet不兼容。
(base) C:\WINDOWS\system32>conda install -c conda-forge fbprophet
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.
Collecting package metadata (repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: /
Found conflicts! Looking for incompatible packages.
This can take several minutes. Press CTRL-C to abort.
failed
UnsatisfiableError: The following specifications were found
to be incompatible with the existing python installation in your environment:
Specifications:
- fbprophet -> python[version='2.7.*|3.5.*|3.6.*|>=2.7,<2.8.0a0|>=3.5,<3.6.0a0|>=3.6,<3.7.0a0|>=3.8,<3.9.0a0|>=3.7,<3.8.0a0']
Your python: python=3.9
3.在Anaconda中创建python3.7的虚拟环境:
conda create -n py37 python=3.7
4.激活并进入虚拟环境,然后再安装fbprophet:
(base) C:\WINDOWS\system32>activate py37
(py37) C:\WINDOWS\system32>conda install -c conda-forge fbprophet
Collecting package metadata (current_repodata.json): done
Solving environment: done
# All requested packages already installed.
(py37) C:\WINDOWS\system32>python
Python 3.7.11 (default, Jul 27 2021, 09:42:29) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import fbprophet
Importing plotly failed. Interactive plots will not work.
可以发现虚拟环境中确实可以正确安装fbprophet,但是导入该库时发掘提示Interactive plots will not work,于是又需要conda install plotly -y来安装plotly库,真是环环相扣,问题百出的一个库。
5.在Anaconda 的python3.7虚拟环境安装完fbprophet之后,后续需要使用fbprophet时有两个方法:1)cmd里面activate your_environment进入所创建的虚拟环境,然后在这个环境里面导入fbprophet,但是使用体验不如jupyterlab好;2)可以通过下述操作把新装的虚拟环境链接到Jupyter Lab的内核,参考链接如下:
如何为 jupyter notebook 设置虚拟环境? - 知乎 (zhihu.com)https://www.zhihu.com/question/484697094/answer/2177731428
下面是知乎里介绍的与Jupyter Lab建立连接的必要操作(详细内容请点击网页链接查看):
先激活环境:
conda activate your_env_name
安装Ipykernal:
pip install ipykernel
建立连接:
python -m ipykernel install --user --name your_env_name
查看链接是否成功:
jupyter kernelspec list
6.重启Jupyter Lab,在Jupyter Lab首页的内核选择下拉清单,能看到此前创建的虚拟环境,切换到该虚拟环境之后,就能顺利导入fbprophet。总算可以愉快的玩fbprophet了!
经过两天的搏杀,总算成功装好fbprophet,后续的使用分析过程会一点点的upload到这里,Tks。