Apple M1芯片设备安装scikit-learn失败:subprocess-exited-with-error报错
M1 Mac 安装 scikit-learn 报错解决办法
问题核心
使用pip3安装scikit-learn时,因scipy依赖的OpenBLAS未找到,导致构建依赖的子进程执行失败,元数据生成出错。同时系统提示pip版本需从22.3.1升级至23.1.2。
报错日志
Collecting scikit-learn Using cached scikit-learn-1.2.2.tar.gz (7.3 MB) Installing build dependencies: started Installing build dependencies: finished with status 'error' error: subprocess-exited-with-error × pip subprocess to install build dependencies did not run successfully. │ exit code: 1 ╰─> [77 lines of output] Ignoring numpy: markers 'python_version == "3.10" and platform_system == "Windows" and platform_python_implementation != "PyPy"' don't match your environment Collecting setuptools Using cached setuptools-67.8.0-py3-none-any.whl (1.1 MB) Collecting wheel Using cached wheel-0.40.0-py3-none-any.whl (64 kB) Collecting Cython>=0.29.24 Using cached Cython-0.29.34-py2.py3-none-any.whl (988 kB) Collecting oldest-supported-numpy Using cached oldest_supported_numpy-2022.11.19-py3-none-any.whl (4.9 kB) Collecting scipy>=1.3.2 Using cached scipy-1.10.1.tar.gz (42.4 MB) Installing build dependencies: started Installing build dependencies: finished with status 'done' Getting requirements to build wheel: started Getting requirements to build wheel: finished with status 'done' Installing backend dependencies: started Installing backend dependencies: finished with status 'done' Preparing metadata (pyproject.toml): started Preparing metadata (pyproject.toml): finished with status 'error' error: subprocess-exited-with-error × Preparing metadata (pyproject.toml) did not run successfully. │ exit code: 1 ╰─> [40 lines of output] The Meson build system Version: 1.1.0 Source dir: /private/var/folders/8t/c7vp1svx67q7d6tfsbc_zrs80000gn/T/pip-install-4eup58s4/scipy_557714486dd74653a564911cc099d6bb Build dir: /private/var/folders/8t/c7vp1svx67q7d6tfsbc_zrs80000gn/T/pip-install-4eup58s4/scipy_557714486dd74653a564911cc099d6bb/.mesonpy-oy6xaeqf/build Build type: native build Project name: SciPy Project version: 1.10.1 C compiler for the host machine: cc (clang 13.0.0 "Apple clang version 13.0.0 (clang-1300.0.29.30)") C linker for the host machine: cc ld64 711 C++ compiler for the host machine: c++ (clang 13.0.0 "Apple clang version 13.0.0 (clang-1300.0.29.30)") C++ linker for the host machine: c++ ld64 711 Cython compiler for the host machine: cython (cython 0.29.34) Host machine cpu family: aarch64 Host machine cpu: aarch64 Compiler for C supports arguments -Wno-unused-but-set-variable: NO Compiler for C supports arguments -Wno-unused-function: YES Compiler for C supports arguments -Wno-conversion: YES Compiler for C supports arguments -Wno-misleading-indentation: YES Compiler for C supports arguments -Wno-incompatible-pointer-types: YES Library m found: YES Fortran compiler for the host machine: gfortran (gcc 13.1.0 "GNU Fortran (Homebrew GCC 13.1.0) 13.1.0") Fortran linker for the host machine: gfortran ld64 711 Compiler for Fortran supports arguments -Wno-conversion: YES Checking if "-Wl,--version-script" : links: NO Program cython found: YES (/private/var/folders/8t/c7vp1svx67q7d6tfsbc_zrs80000gn/T/pip-build-env-8q5edqdt/overlay/bin/cython) Program python found: YES (/opt/homebrew/Caskroom/miniforge/base/envs/pythonProject/bin/python) Found pkg-config: /opt/homebrew/bin/pkg-config (0.29.2) Program pythran found: YES (/private/var/folders/8t/c7vp1svx67q7d6tfsbc_zrs80000gn/T/pip-build-env-8q5edqdt/overlay/bin/pythran) Run-time dependency threads found: YES Library npymath found: YES Library npyrandom found: YES Did not find CMake 'cmake' Found CMake: NO Run-time dependency openblas found: NO (tried pkgconfig, framework and cmake) Run-time dependency openblas found: NO (tried pkgconfig and framework) ../../scipy/meson.build:134:7: ERROR: Dependency "OpenBLAS" not found, tried pkgconfig and framework A full log can be found at /private/var/folders/8t/c7vp1svx67q7d6tfsbc_zrs80000gn/T/pip-install-4eup58s4/scipy_557714486dd74653a564911cc099d6bb/.mesonpy-oy6xaeqf/build/meson-logs/meson-log.txt + meson setup --prefix=/Library/Frameworks/Python.framework/Versions/3.11 /private/var/folders/8t/c7vp1svx67q7d6tfsbc_zrs80000gn/T/pip-install-4eup58s4/scipy_557714486dd74653a564911cc099d6bb /private/var/folders/8t/c7vp1svx67q7d6tfsbc_zrs80000gn/T/pip-install-4eup58s4/scipy_557714486dd74653a564911cc099d6bb/.mesonpy-oy6xaeqf/build --native-file=/private/var/folders/8t/c7vp1svx67q7d6tfsbc_zrs80000gn/T/pip-install-4eup58s4/scipy_557714486dd74653a564911cc099d6bb/.mesonpy-native-file.ini -Ddebug=false -Doptimization=2 [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. error: metadata-generation-failed × Encountered error while generating package metadata. ╰─> See above for output. note: This is an issue with the package mentioned above, not pip. hint: See above for details. [notice] A new release of pip available: 22.3.1 -> 23.1.2 [notice] To update, run: pip install --upgrade pip [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. error: subprocess-exited-with-error × pip subprocess to install build dependencies did not run successfully. │ exit code: 1 ╰─> See above for output. note: This error originates from a subprocess, and is likely not a problem with pip. [notice] A new release of pip available: 22.3.1 -> 23.1.2 [notice] To update, run: pip install --upgrade pip
解决方案
方案1:通过pip安装(手动处理依赖)
- 升级pip
pip3 install --upgrade pip - 安装OpenBLAS
用Homebrew安装OpenBLAS:brew install openblas - 指定OpenBLAS路径安装scikit-learn
执行以下命令,让pip找到OpenBLAS依赖:OPENBLAS=$(brew --prefix openblas) pip3 install scikit-learn
方案2:使用conda安装(推荐,自动处理依赖)
如果你的环境是基于conda(比如miniforge,适配M1芯片),直接执行:
conda install scikit-learn
conda会自动配置所有依赖项,无需手动处理OpenBLAS路径问题。
内容的提问来源于stack exchange,提问作者jason li
相关产品推荐
相关产品推荐

