@[TOC]prophet踩坑记
pip install pystan
用pip安装pystan,能够安装,pip list 与conda list都能看到列表里面有pystan.但是执行以下python程序会报错。
import pystan
model_code = 'parameters {real y;} model {y ~ normal(0,1);}'
model = pystan.StanModel(model_code=model_code)
y = model.sampling().extract()['y']
y.mean() # 安装成功会输出接近0的值。
报错为:
WARNING:pystan:MSVC compiler is not supported
error: Unable to find vcvarsall.bat
按照博客(Python安装fbprophet以及测试)的解释是因为没有安装MinGW-w64,之后按照博客(2019-08-19安装MinGW-w64-gcc编译器)然而安装MinGW-w64和配置环境后,出现出现同样的错误。
在安装有MinGW-w64的基础上,按照博客(Facebook 开源的 Python 预测工具)的方法,修改Python内部编译设置,方法为在Python安装目录下(示例C:\Python36\Lib\distutils),新建distutils.cfg文件,文件内容为
[build]
compiler = mingw32
注:我是在anaconda的Lib\distutils目录下创建该文件。
运行上述python文件。没有WARNING:pystan:MSVC compiler is not supported的警告,但有其他报错。这种情况是其他网友没有遇到的,只好另寻他路。果断卸载MinW-w64。
博客(彻底解决 error: Unable to find vcvarsall.bat)警告:WARNING:pystan:MSVC compiler is not supported和报错:error: Unable to find vcvarsall.bat的处理方式是下载安装VS,我本身是安装了VS 2019的,问题没有解决。
WARNING:pystan:MSVC compiler is not supported
error: Unable to find vcvarsall.bat
怀疑VS版本不对,一怒之下卸载VS 2019,继续运行以上python程序。报错如下:
error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools"
按照博客(Python 典藏篇-Microsoft Visual C++ 14.0 is required,官方c++运行库工具一键式解决!)安装VC 2015并配置环境变量后,运行上述python程序。报错如下:
"... ... Microsoft Visual Studio 14.0\VC\bin\cl.exe" failed with exit status 1
问题没有解决。
查询各种博客后未解决。突发奇想在anaconda的Lib\distutils目录下创建distutils.cfg该文件.运行上述python程序,报错如下:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-2-485e591fbc68> in <module>
1 model_code = 'parameters {real y;} model {y ~ normal(0,1);}'
----> 2 model = pystan.StanModel(model_code=model_code)
3 y = model.sampling().extract()['y']
4 y.mean() # with luck the result will be near 0
C:\ProgramData\Anaconda3\Lib\site-packages\pystan\model.py in __init__(self, file, charset, model_name, model_code, stanc_ret, include_paths, boost_lib, eigen_lib, verbose, obfuscate_model_name, extra_compile_args, allow_undefined, include_dirs, includes)
376
377 try:
--> 378 build_extension.run()
379 finally:
380 if redirect_stderr:
C:\ProgramData\Anaconda3\lib\distutils\command\build_ext.py in run(self)
307 verbose=self.verbose,
308 dry_run=self.dry_run,
--> 309 force=self.force)
310 customize_compiler(self.compiler)
311 # If we are cross-compiling, init the compiler now (if we are not
C:\ProgramData\Anaconda3\lib\distutils\ccompiler.py in new_compiler(plat, compiler, verbose, dry_run, force)
1029 # with classes that expect verbose to be the first positional
1030 # argument.
-> 1031 return klass(None, dry_run, force)
1032
1033
C:\ProgramData\Anaconda3\lib\distutils\cygwinccompiler.py in __init__(self, verbose, dry_run, force)
283 def __init__(self, verbose=0, dry_run=0, force=0):
284
--> 285 CygwinCCompiler.__init__ (self, verbose, dry_run, force)
286
287 # ld_version >= "2.13" support -shared so use it instead of
C:\ProgramData\Anaconda3\lib\distutils\cygwinccompiler.py in __init__(self, verbose, dry_run, force)
127 # same as the rest of binutils ( also ld )
128 # dllwrap 2.10.90 is buggy
--> 129 if self.ld_version >= "2.10.90":
130 self.linker_dll = "gcc"
131 else:
TypeError: '>=' not supported between instances of 'NoneType' and 'str'
彻底失去了解决错误的方案。
以上都是pip按照pystan的情况下说产生的问题,决定用conda 安装pystan。
最终:pystan安装成功,fbprophet也轻松安装成功,实现了prophet的简易安装。
见我的另一篇博客:
Window10系统下安装简易安装prophet:https://blog.csdn.net/qq_40583178/article/details/105127517