You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PyMC3导入失败求助:已安装但执行import pymc3 as pm报错

PyMC3导入失败问题

已安装PyMC3,但执行import pymc3 as pm时导入失败,错误信息如下:

WARNING (theano.configdefaults): g++ not available, if using conda: `conda install m2w64-toolchain`
C:\Users\miallana\AppData\Local\Programs\Python\Python39\lib\site-packages\theano\configdefaults.py:560: UserWarning: DeprecationWarning: there is no c++ compiler.This is deprecated and with Theano 0.11 a c++ compiler will be mandatory
  warnings.warn("DeprecationWarning: there is no c++ compiler."
WARNING (theano.configdefaults): g++ not detected ! Theano will be unable to execute optimized C-implementations (for both CPU and GPU) and will default to Python implementations. Performance will be severely degraded. 
To remove this warning, set Theano flags cxx to an empty string.
WARNING (theano.tensor.blas): Using NumPy C-API based implementation for BLAS functions.
Traceback (most recent call last):
  File "c:\Users\miallana\Documents\project\stats.py", line 26, in <module>
    import pymc3 as pm
  File "C:\Users\miallana\AppData\Local\Programs\Python\Python39\lib\site-packages\pymc3\__init__.py", line 41, in <module>
    from .distributions import *
  File "C:\Users\miallana\AppData\Local\Programs\Python\Python39\lib\site-packages\pymc3\distributions\__init__.py", line 15, in <module>
    from . import timeseries
  File "C:\Users\miallana\AppData\Local\Programs\Python\Python39\lib\site-packages\pymc3\distributions\timeseries.py", line 22, in <module>
    from pymc3.util import get_variable_name
  File "C:\Users\miallana\AppData\Local\Programs\Python\Python39\lib\site-packages\pymc3\util.py", line 19, in <module>
    import xarray
  File "C:\Users\miallana\AppData\Local\Programs\Python\Python39\lib\site-packages\xarray\__init__.py", line 1, in <module>
    from . import testing, tutorial
  File "C:\Users\miallana\AppData\Local\Programs\Python\Python39\lib\site-packages\xarray\testing.py", line 9, in <module>
    from xarray.core import duck_array_ops, formatting, utils
  File "C:\Users\miallana\AppData\Local\Programs\Python\Python39\lib\site-packages\xarray\core\duck_array_ops.py", line 26, in <module>
    from . import dask_array_compat, dask_array_ops, dtypes, npcompat, nputils
  File "C:\Users\miallana\AppData\Local\Programs\Python\Python39\lib\site-packages\xarray\core\npcompat.py", line 72, in <module>
    _SupportsDType[np.dtype],
  File "C:\Users\miallana\AppData\Local\Programs\Python\Python39\lib\typing.py", line 262, in inner
    return func(*args, **kwds)
  File "C:\Users\miallana\AppData\Local\Programs\Python\Python39\lib\typing.py", line 980, in __class_getitem__
    _check_generic(cls, params, len(cls.__parameters__))
  File "C:\Users\miallana\AppData\Local\Programs\Python\Python39\lib\site-packages\typing_extensions.py", line 92, in _check_generic
    raise TypeError(f"{cls} is not a generic class")
TypeError: <class 'numpy.typing._dtype_like._SupportsDType'> is not a generic class

通过pip install pymc3完成安装,之后尝试过两个公开解决方案,但问题仍未解决。未使用conda环境。

环境配置:

Python 3.9.1
pymc3 3.9.3
Theano 1.0.5
Windows 10

解决方案

  • 修复版本兼容问题
    导入失败的核心原因是xarray与当前NumPy版本不兼容,导致泛型类调用出错。执行以下命令安装兼容的xarray版本:
    pip install xarray==0.20.2
    
  • 解决g++缺失警告(可选)
    虽然不是导入失败的直接原因,但g++缺失会大幅降低Theano运行性能。Windows环境下可通过两种方式安装编译器:
    1. 下载安装MinGW-w64(选择x86_64架构),将mingw64/bin路径添加到系统环境变量PATH中;
    2. 安装Microsoft Visual C++ Build Tools,勾选“C++构建工具”组件。

内容的提问来源于stack exchange,提问作者Hattori

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.24 21:54:17