pystan的安装教程
简介
安装Pystan需要安装Python、C++ compiler、Python dependencies,因为Pystan需要C依赖库,采用python自带的环境安装,所需依赖库很难配置完整,所以使用Ansconda来进行安装。
Anaconda下载、安装
链接:https://pan.baidu.com/s/1e3xfh0YOZ8sV2kGFoANJSg
提取码:1j25
Anaconda的安装教程请参阅此博客。
安装完成后,打开
键入
python --version
可以查看python对应的版本型号
C++ compiler下载、安装(使用Anaconda可不安装)
链接:https://pan.baidu.com/s/196_TJ6CqzQmUQ9Q_Hqxe8Q
提取码:bonb
根据步骤逐步安装即可
安装python依赖库(可新建虚拟环境)
打开win+R,输入cmd打开win系统命令窗口。
创建虚拟环境
conda create -name fbp_env python=3.7
激活虚拟环境
activate fbp_env
安装MingW-w64编译器
conda install libpython m2w64-toolchain -c msys2
安装cpthon
conda install numpy cython -c conda-forge
安装matplotlib scipy pandas
conda install matplotlib scipy pandas -c conda-forge
安装PyStan
conda install pystan -c conda-forge
安装jupyter
conda install jupyter
安装nb_conda_kernels工具
conda install nb_conda_kernels
打开jupyter选择需要的编译环境
验证PyStan是否安装成功
import pystan
import numpy as np
ocode = """
data {
int<lower=1> N;
real y[N];
}
parameters {
real mu;
}
model {
y ~ normal(mu, 1);
}
"""
sm = pystan.StanModel(model_code=ocode)
y2 = np.random.normal(size=20)
np.mean(y2)
op = sm.optimizing(data=dict(y=y2, N=len(y2)))
op
下一步计划
待完成fbprophet的安装和验证,参见博客。
问题总结
一、如安装过程中提示:“无法定位程序输入点 OPENSSL_sk_new_reserve 于动态链接库 D:\Program Files\Anaconda3\Library\bin\libssl-1_1-x64.dll上”
解决方案:
1、将D:\Program Files\Anaconda3\Library\bin里的libssl-1_1-x64.dll重命名。
2、将D:\Program Files\Anaconda3\DLLs下的libssl-1_1-x64.dll文件拷贝到D:\Program Files\Anaconda3\Library\bin里,将原来的文件替换。
二、安装过程网络太慢,可以使用更换源
1、打开win+R,输入cmd打开win系统命令窗口。
2、执行conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
3、执行conda config --set show_channel_urls yes
4、在目录 C:\Users<你的用户名> 下就会生成配置文件.condarc,可查看相应的源配置。
5、将.condarc的内容改为如下:
channels:
- defaults
show_channel_urls: true
default_channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
custom_channels:
conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
参考
【1】fbprophet安装及使用笔记
【2】pystan官网安装教程