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

多款Mac环境下从源码构建SciPy失败,求排查建议

问题概述

我和朋友分别在以下环境尝试源码构建SciPy:

  • Intel Mac + Catalina + CPython 3.11
  • M1 Mac + Ventura + CPython 3.11 / PyPy 3.10
  • Intel Mac + Monterey + CPython 3.9

严格遵循SciPy官方文档步骤操作:

  1. 执行 xcode-select --install 安装Xcode命令行工具
  2. 通过 brew install gfortran openblas pkg-config 安装依赖
  3. 执行 pip install scipy --no-binary scipy 触发源码构建

所有尝试均失败,核心报错包括:

  • OpenBLAS依赖未找到:
    ../scipy/meson.build:159:9: ERROR: Dependency "OpenBLAS" not found, tried pkgconfig, framework and cmake
    
  • BLAS库未检测到:
    ../../numpy/meson.build:207:4: ERROR: Problem encountered: No BLAS library detected!
    
  • Fortran链接器检测失败:
    ../meson.build:82:0: ERROR: Unable to detect linker for compiler `gfortran -Wl,--version`
    
  • CMake相关错误:
    Problem with the CMake installation, aborting build. CMake executable is cmake
    
  • 后端依赖安装失败:pip subprocess to install backend dependencies did not run successfully

PyPy环境无预编译.whl包,必须源码构建,但目前所有环境均无法完成构建。想问是操作有误还是应该提交Bug?

排查与解决建议

1. 手动配置OpenBLAS环境变量

Homebrew安装的OpenBLAS可能未被pkg-config自动识别,需手动指定路径:

  • 先执行 brew info openblas 获取安装路径(M1 Mac通常为/opt/homebrew/opt/openblas,Intel Mac为/usr/local/opt/openblas)
  • 构建前导出环境变量:
    export PKG_CONFIG_PATH=$(brew --prefix openblas)/lib/pkgconfig
    export OPENBLAS=$(brew --prefix openblas)
    
    再重新执行构建命令

2. 修复CMake安装

报错指向CMake问题,先确认是否通过Homebrew安装了CMake:

brew install cmake

安装后检查路径有效性:which cmake 应返回Homebrew安装路径(如/opt/homebrew/bin/cmake)

3. 验证gfortran与链接器兼容性

部分Mac环境下gfortran可能与系统链接器不兼容,先执行 gfortran -Wl,--version 测试输出,若报错则重新安装gfortran:

brew reinstall gfortran

4. 确保虚拟环境继承环境变量

虚拟环境可能未继承系统PATH和PKG_CONFIG_PATH,构建前需在虚拟环境内重新导出上述环境变量,或临时用--system-site-packages参数创建虚拟环境测试(不推荐用于生产环境)

是否需要提交Bug?

如果上述所有排查步骤均尝试后仍失败,且已严格遵循官方文档、在多架构/多OS/多Python版本环境下均复现问题,那么这大概率是SciPy构建系统在Mac环境下的兼容性Bug。建议:

  1. 整理完整环境信息(OS版本、Python/PyPy版本、Homebrew版本、依赖包版本)
  2. 附上完整构建日志
  3. 前往SciPy的GitHub仓库提交Issue,说明复现步骤、环境信息及已尝试的排查措施

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.09 10:16:02