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

Mac系统Jupyter中导入train_test_split遇AttributeError问题求助

解决scikit-learn 1.2.0中DistanceMetric32属性缺失的问题

这个报错通常是scikit-learn安装不完整、Mac架构与包编译版本不匹配,或是依赖库版本冲突导致的,以下是具体解决步骤:

  • 确认导入路径正确性
    确保从正确模块导入train_test_split:

    from sklearn.model_selection import train_test_split
    
  • 重新安装scikit-learn
    卸载现有损坏版本后重装:

    pip uninstall -y scikit-learn
    pip install scikit-learn==1.2.0
    

    若使用conda环境:

    conda remove scikit-learn
    conda install scikit-learn=1.2.0
    
  • 适配Mac ARM架构(M1/M2等芯片)
    若你的Mac是ARM架构,预编译包可能存在兼容问题,尝试源码编译安装:

    pip uninstall -y scikit-learn
    pip install scikit-learn==1.2.0 --no-binary :all:
    

    或使用conda-forge提供的适配版本:

    conda install -c conda-forge scikit-learn=1.2.0
    
  • 更新依赖库
    scikit-learn依赖numpy、scipy等库,版本不匹配也会引发异常:

    pip install --upgrade numpy scipy
    
  • 重启Jupyter内核
    完成上述操作后,重启Jupyter内核再尝试导入函数。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.08 23:01:10