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

无法从sklearn.exceptions导入InconsistentVersionWarning问题求助

问题

调整NumPy版本解决了之前的版本错误后,导入scikit-learn时持续出现以下导入错误:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
/Users/matheusbrandaofreire/CEMIG/analises-watson-assistant/notebooks/0-65-ExperimentoWatsonAssistant.ipynb Célula 6 line 5
      3 import numpy; print("NumPy", numpy.__version__)
      4 import scipy; print("SciPy", scipy.__version__)
----> 5 import sklearn; print("Scikit-Learn", sklearn.__version__)

File ~/opt/miniconda3/lib/python3.9/site-packages/sklearn/__init__.py:83
     69     # We are not importing the rest of scikit-learn during the build
     70     # process, as it may not be compiled yet
     71 else:
   (...)
     77     # later is linked to the OpenMP runtime to make it possible to introspect
     78     # it and importing it first would fail if the OpenMP dll cannot be found.
     79     from . import (
     80         __check_build,  # noqa: F401
     81         _distributor_init,  # noqa: F401
     82     )
----> 83     from .base import clone
     84     from .utils._show_versions import show_versions
     86     __all__ = [
     87         "calibration",
     88         "cluster",
   (...)
    129         "show_versions",
    130     ]

File ~/opt/miniconda3/lib/python3.9/site-packages/sklearn/base.py:18
     16 from . import __version__
     17 from ._config import config_context, get_config
----> 18 from .exceptions import InconsistentVersionWarning
     19 from .utils import _IS_32BIT
     20 from .utils._estimator_html_repr import estimator_html_repr

ImportError: cannot import name 'InconsistentVersionWarning' from 'sklearn.exceptions' (/Users/matheusbrandaofreire/opt/miniconda3/lib/python3.9/site-packages/sklearn/exceptions.py)

解决方案

  • 彻底卸载并重装scikit-learn
    执行卸载命令:
    pip uninstall -y scikit-learn
    
    重装时可指定与当前Python、NumPy版本兼容的版本(例如Python3.9适配scikit-learn==1.2.2):
    pip install scikit-learn==1.2.2
    
  • 检查安装文件完整性
    查看路径~/opt/miniconda3/lib/python3.9/site-packages/sklearn/exceptions.py,确认文件中存在InconsistentVersionWarning类。若不存在,说明安装包损坏,必须重装。
  • 清理conda环境后重装(若使用conda)
    先清理缓存:
    conda clean --all
    
    再重新安装scikit-learn:
    conda install scikit-learn
    
  • 验证依赖兼容性
    运行以下命令检查所有依赖版本是否匹配,修复提示的问题:
    pip check
    

内容的提问来源于stack exchange,提问作者Matheus Brandão

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.06 09:07:37