pymc3+arviz+theano windows安装,避免踩坑

尝试安装了很多次,一直报各种各样的错误。找了很久,按照这个顺序安装必成功!

conda create -n pm -c conda-forge "python=3.8" libpython mkl-service m2w64-toolchain numba python-graphviz scipy
conda activate pm
pip install h5py
conda install -c anaconda netcdf4
pip install pymc3==3.11.0

此时,如果你import pymc3就会报错 :

AttributeError: module 'numpy' has no attribute 'bool'.
`np.bool` was a deprecated alias for the builtin `bool`. To avoid this error in existing code, use `bool` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.bool_` here.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations。

不要紧张,此时我们只需要降低版本,将numpy降级到:pip install numpy==1.21.6,现在就可以正常使用了。

如果此时你尝试运行下面的测试代码,这时就会报错AttributeError: module 'arviz' has no attribute 'from_pymc3',不要紧张,降低arviz的版本:pip install arviz==0.12,就可以了。

PyMC Example Gallery — PyMC example gallery

下面是一段来自上述官网的测试代码,可以用于验证pymc3安装的正确性。 

import arviz as az
import matplotlib.pyplot as plt
import numpy as np
import pymc3 as pm
RANDOM_SEED = 8927
np.random.seed(RANDOM_SEED)
az.style.use("arviz-darkgrid")
# True parameter values
alpha, sigma = 1, 1
beta = [1, 2.5]

# Size of dataset
size = 100

# Predictor variable
X1 = np.random.randn(size)
X2 = np.random.randn(size) * 0.2

# Simulate outcome variable
Y = alpha + beta[0] * X1 + beta[1] * X2 + np.random.randn(size) * sigma
fig, axes = plt.subplots(1, 2, sharex=True, figsize=(10, 4))
axes[0].scatter(X1, Y, alpha=0.6)
axes[1].scatter(X2, Y, alpha=0.6)
axes[0].set_ylabel("Y")
axes[0].set_xlabel("X1")
axes[1].set_xlabel("X2")
basic_model = pm.Model()
if __name__ == '__main__':
 with basic_model:

    # Priors for unknown model parameters
    alpha = pm.Normal("alpha", mu=0, sigma=10)
    beta = pm.Normal("beta", mu=0, sigma=10, shape=2)
    sigma = pm.HalfNormal("sigma", sigma=1)

    # Expected value of outcome
    mu = alpha + beta[0] * X1 + beta[1] * X2

    # Likelihood (sampling distribution) of observations
    Y_obs = pm.Normal("Y_obs", mu=mu, sigma=sigma, observed=Y)

# instantiate sampler
    step = pm.Slice()

    # draw 5000 posterior samples
    trace = pm.sample(5000, step=step, return_inferencedata=False)
    az.plot_trace(trace)
    plt.show()

附录

pip list

Package             Version
------------------- -----------
arviz               0.12.0
Brotli              1.0.9
certifi             2024.8.30
cffi                1.17.1
cftime              1.6.2
charset-normalizer  3.3.2
contourpy           1.1.1
cycler              0.12.1
dill                0.3.9
fastprogress        1.0.3
filelock            3.16.1
fonttools           4.54.1
graphviz            0.12
h2                  4.0.0
h5netcdf            1.1.0
h5py                3.11.0
hpack               4.0.0
hyperframe          6.0.1
idna                3.10
importlib_metadata  8.5.0
importlib_resources 6.4.5
kiwisolver          1.4.7
llvmlite            0.41.0
matplotlib          3.7.5
mkl-fft             1.3.8
mkl-random          1.2.4
mkl-service         2.4.0
netCDF4             1.6.2
numba               0.58.1
numpy               1.21.6
packaging           24.1
pandas              2.0.3
patsy               0.5.6
pillow              10.4.0
pip                 24.2
platformdirs        4.3.6
pooch               1.8.2
pycparser           2.22
pymc3               3.11.0
pyparsing           3.1.4
PySocks             1.7.1
python-dateutil     2.9.0.post0
pytz                2024.2
requests            2.32.3
scipy               1.10.1
setuptools          75.1.0
six                 1.16.0
Theano-PyMC         1.1.0
typing_extensions   4.12.2
tzdata              2024.2
urllib3             2.2.3
wheel               0.44.0
win_inet_pton       1.1.0
xarray              2023.1.0
xarray-einstats     0.5.1
zipp                3.20.2
zstandard           0.22.0

conda list

# Name                    Version                   Build  Channel
arviz                     0.12.0                   pypi_0    pypi
blas                      1.0                         mkl    anaconda
brotli-python             1.0.9            py38hd77b12b_8    anaconda
bzip2                     1.0.8                h2466b09_7    conda-forge
ca-certificates           2024.9.24            haa95532_0    anaconda
certifi                   2024.8.30        py38haa95532_0    anaconda
cffi                      1.17.1           py38h827c3e9_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
cftime                    1.6.2            py38h080aedc_0    anaconda
charset-normalizer        3.3.2              pyhd8ed1ab_0    conda-forge
contourpy                 1.1.1                    pypi_0    pypi
cycler                    0.12.1                   pypi_0    pypi
dill                      0.3.9                    pypi_0    pypi
fastprogress              1.0.3                    pypi_0    pypi
filelock                  3.16.1                   pypi_0    pypi
fonttools                 4.54.1                   pypi_0    pypi
graphviz                  2.38.0                        4    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
h2                        4.0.0            py38haa95532_3    anaconda
h5netcdf                  1.1.0                    pypi_0    pypi
h5py                      3.11.0                   pypi_0    pypi
hdf4                      4.2.13               h712560f_2    anaconda
hdf5                      1.12.1               h51c971a_3    anaconda
hpack                     4.0.0              pyh9f0ad1d_0    conda-forge
hyperframe                6.0.1              pyhd8ed1ab_0    conda-forge
icc_rt                    2022.1.0             h6049295_2    anaconda
idna                      3.10               pyhd8ed1ab_0    conda-forge
importlib-metadata        8.5.0              pyha770c72_0    conda-forge
importlib-resources       6.4.5                    pypi_0    pypi
importlib_metadata        8.5.0                hd8ed1ab_0    conda-forge
intel-openmp              2023.1.0         h59b6b97_46320    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
jpeg                      9e                   h827c3e9_3    anaconda
kiwisolver                1.4.7                    pypi_0    pypi
libblas                   3.9.0              20_win64_mkl    conda-forge
libcblas                  3.9.0              20_win64_mkl    conda-forge
libcurl                   7.88.1               h86230a5_2    anaconda
libffi                    3.4.2                h8ffe710_5    conda-forge
libhwloc                  2.11.1          default_h8125262_1000    conda-forge
libiconv                  1.17                 hcfcfb64_2    conda-forge
liblapack                 3.9.0              20_win64_mkl    conda-forge
libnetcdf                 4.8.1                h6685c40_4    anaconda
libpython                 2.1                      py38_0    anaconda
libsqlite                 3.46.1               h2466b09_0    conda-forge
libssh2                   1.11.0               h291bd65_0    anaconda
libxml2                   2.13.1               h24da03e_2    anaconda
libzip                    1.8.0                h289538f_1    anaconda
llvmlite                  0.41.0           py38hf2fb9eb_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
lz4-c                     1.9.4                h2bbff1b_1    anaconda
m2w64-binutils            2.25.1                        5    conda-forge
m2w64-bzip2               1.0.6                         6    conda-forge
m2w64-crt-git             5.0.0.4636.2595836               2    conda-forge
m2w64-gcc                 5.3.0                         6    conda-forge
m2w64-gcc-ada             5.3.0                         6    conda-forge
m2w64-gcc-fortran         5.3.0                         6    conda-forge
m2w64-gcc-libgfortran     5.3.0                         6    conda-forge
m2w64-gcc-libs            5.3.0                         7    conda-forge
m2w64-gcc-libs-core       5.3.0                         7    conda-forge
m2w64-gcc-objc            5.3.0                         6    conda-forge
m2w64-gmp                 6.1.0                         2    conda-forge
m2w64-headers-git         5.0.0.4636.c0ad18a               2    conda-forge
m2w64-isl                 0.16.1                        2    conda-forge
m2w64-libiconv            1.14                          6    conda-forge
m2w64-libmangle-git       5.0.0.4509.2e5a9a2               2    conda-forge
m2w64-libwinpthread-git   5.0.0.4634.697f757               2    conda-forge
m2w64-make                4.1.2351.a80a8b8               2    conda-forge
m2w64-mpc                 1.0.3                         3    conda-forge
m2w64-mpfr                3.1.4                         4    conda-forge
m2w64-pkg-config          0.29.1                        2    conda-forge
m2w64-toolchain           5.3.0                         7    conda-forge
m2w64-tools-git           5.0.0.4592.90b8472               2    conda-forge
m2w64-windows-default-manifest 6.4                           3    conda-forge
m2w64-winpthreads-git     5.0.0.4634.697f757               2    conda-forge
m2w64-zlib                1.2.8                        10    conda-forge
matplotlib                3.7.5                    pypi_0    pypi
mkl                       2023.2.0         h6a75c08_50497    conda-forge
mkl-service               2.4.0            py38h2bbff1b_1    anaconda
mkl_fft                   1.3.8            py38h2bbff1b_0    anaconda
mkl_random                1.2.4            py38h59b6b97_0    anaconda
msys2-conda-epoch         20160418                      1    conda-forge
netcdf4                   1.6.2            py38hda396d2_0    anaconda
numba                     0.58.1           py38hd77b12b_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
numpy                     1.21.6                   pypi_0    pypi
openssl                   3.0.15               h827c3e9_0    anaconda
packaging                 24.1               pyhd8ed1ab_0    conda-forge
pandas                    2.0.3                    pypi_0    pypi
patsy                     0.5.6                    pypi_0    pypi
pillow                    10.4.0                   pypi_0    pypi
pip                       24.2               pyh8b19718_1    conda-forge
platformdirs              4.3.6              pyhd8ed1ab_0    conda-forge
pooch                     1.8.2              pyhd8ed1ab_0    conda-forge
pthreads-win32            2.9.1                hfa6e2cd_3    conda-forge
pycparser                 2.22               pyhd8ed1ab_0    conda-forge
pymc3                     3.11.0                   pypi_0    pypi
pyparsing                 3.1.4                    pypi_0    pypi
pysocks                   1.7.1              pyh0701188_6    conda-forge
python                    3.8.20               h8205438_0    anaconda
python-dateutil           2.9.0.post0              pypi_0    pypi
python-graphviz           0.12                       py_0    conda-forge
pytz                      2024.2                   pypi_0    pypi
requests                  2.32.3             pyhd8ed1ab_0    conda-forge
scipy                     1.10.1           py38hdcfc7df_1    anaconda
setuptools                75.1.0             pyhd8ed1ab_0    conda-forge
six                       1.16.0                   pypi_0    pypi
sqlite                    3.45.3               h2bbff1b_0    anaconda
tbb                       2021.13.0            hc790b64_0    conda-forge
theano-pymc               1.1.0                    pypi_0    pypi
tk                        8.6.13               h5226925_1    conda-forge
typing-extensions         4.12.2                   pypi_0    pypi
tzdata                    2024.2                   pypi_0    pypi
ucrt                      10.0.22621.0         h57928b3_0    conda-forge
urllib3                   2.2.3              pyhd8ed1ab_0    conda-forge
vc                        14.3                h8a93ad2_21    conda-forge
vc14_runtime              14.40.33810         ha82c5b3_21    conda-forge
vs2015_runtime            14.40.33810         h3bf8584_21    conda-forge
wheel                     0.44.0             pyhd8ed1ab_0    conda-forge
win_inet_pton             1.1.0              pyh7428d3b_7    conda-forge
xarray                    2023.1.0                 pypi_0    pypi
xarray-einstats           0.5.1                    pypi_0    pypi
xz                        5.4.6                h8cc25b3_1    anaconda
zipp                      3.20.2             pyhd8ed1ab_0    conda-forge
zlib                      1.2.13               h8cc25b3_1    anaconda
zstandard                 0.22.0           py38h3469f8a_0    anaconda
zstd                      1.5.5                hd43e919_2    anaconda

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值