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

安装niwidgets时scikit-learn编译wheel失败问题求助

安装niwidgets时scikit-learn Wheel编译失败问题处理

错误信息

安装niwidgets过程中触发scikit-learn的wheel编译错误,核心报错如下:

** Building wheel for scikit-learn (setup.py) ... error
error: subprocess-exited-with-error

python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [820 lines of output]
      /private/var/folders/t_/tkgl1f8j7y14c3d40pcymqmw0000gn/T/pip-install-oqhx_cr5/scikit-learn_1cef91db2c464800815e767404a4ca2f/setup.py:12: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
        from pkg_resources import parse_version
      Partial import of sklearn during the build process.
      /private/var/folders/t_/tkgl1f8j7y14c3d40pcymqmw0000gn/T/pip-install-oqhx_cr5/scikit-learn_1cef91db2c464800815e767404a4ca2f/setup.py:242: DeprecationWarning:

        `numpy.distutils` is deprecated since NumPy 1.23.0, as a result
        of the deprecation of `distutils` itself. It will be removed for
        Python >= 3.12. For older Python versions it will remain present.
        It is recommended to use `setuptools < 60.0` for those Python versions.}

注意:此错误源自子进程,大概率并非pip的问题。

后续错误链:

ERROR: Failed building wheel for scikit-learn
Running setup.py clean for scikit-learn
Failed to build scikit-learn
ERROR: Could not build wheels for scikit-learn, which is required to install pyproject.toml-based projects

解决步骤

1. 降级setuptools版本

根据报错提示,numpy.distutils已废弃,需使用指定版本的setuptools:

pip install "setuptools<60.0"

执行后重新安装niwidgets:

pip install niwidgets

2. 安装预编译的scikit-learn包

跳过本地编译环节,直接使用预编译版本:

  • 通过conda安装(适配多系统):
conda install scikit-learn
  • 或用pip强制安装预编译包:
pip install scikit-learn --only-binary :all:

完成后再执行niwidgets安装命令。

3. 调整Python与NumPy版本兼容性

确保Python版本低于3.12(numpy.distutils在Python 3.12+被移除),同时安装兼容的NumPy版本:

pip install numpy==1.22.4

之后重新尝试安装niwidgets。

4. 更新pip至最新版本

旧版pip可能存在wheel处理逻辑缺陷,先更新再重试:

pip install --upgrade pip

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.25 09:46:21