Win11 Cygwin(Python3.9)下pip安装scipy因long double支持不足报错
问题说明
- 运行环境:Win11 系统 Cygwin 终端,Python 3.9.10
- 预期操作:执行命令
python3 -m pip install scipy安装scipy库 - 前置准备:已通过Cygwin安装器部署全部已知依赖:gcc-core、gcc-g++、libopenblas、liblapack、liblapack-devel、gcc-fortran、python39-devel、python39-wheel,已验证python-devel开发文件安装正常
- 故障表现:安装到编译阶段直接终止,核心错误为Boost库静态断言失败,提示当前平台long double支持不足,无法可靠实现数学特殊函数,最终g++编译
beta_ufunc.cxx文件时退出状态为1,无法构建scipy wheel包,pyproject.toml类项目安装流程失败。
核心错误日志片段:
/tmp/pip-install-lggt3n7k/scipy_d9ae94430a22449eb2927159d9f7ad01/scipy/_lib/boost/boost/math/tools/promotion.hpp:148:37: error: static assertion failed: Sorry, but this platform does not have sufficient long double support for the special functions to be reliably implemented. error: Command "g++ -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -DBOOST_MATH_DOMAIN_ERROR_POLICY=ignore_error -DBOOST_MATH_EVALUATION_ERROR_POLICY=user_error -DBOOST_MATH_OVERFLOW_ERROR_POLICY=user_error -DBOOST_MATH_PROMOTE_DOUBLE_POLICY=false -Iscipy/stats/_boost/include/ -Iscipy/stats/_boost/src/ -I/tmp/pip-build-env-ms79kstb/overlay/lib/python3.9/site-packages/numpy/core/include -I/tmp/pip-install-lggt3n7k/scipy_d9ae94430a22449eb2927159d9f7ad01/scipy/_lib/boost -I/tmp/pip-build-env-ms79kstb/overlay/lib/python3.9/site-packages/numpy/core/include -I/usr/include/python3.9 -c scipy/stats/_boost/src/beta_ufunc.cxx -o build/temp.cygwin-3.3.5-x86_64-3.9/scipy/stats/_boost/src/beta_ufunc.o -MMD -MF build/temp.cygwin-3.3.5-x86_64-3.9/scipy/stats/_boost/src/beta_ufunc.o.d -std=c++14" failed with exit status 1 [end of output]
最终终端返回报错:
ERROR: Failed building wheel for scipy
ERROR: Could not build wheels for scipy, which is required to install pyproject.toml-based projects
解决方案
按优先级从高到低排列,可根据自身需求选择:
- 优先使用Cygwin官方源预编译包安装:打开Cygwin安装器,在包列表中搜索
python39-scipy勾选安装即可。官方源内的包已经针对Cygwin平台的long double特性做过适配,不会触发Boost静态断言,无需手动处理编译依赖,稳定性最高。 - 若必须通过pip安装,强制安装预编译wheel绕开本地编译:执行安装命令时添加参数禁止源码编译,同时选择对Cygwin兼容性更好的低版本scipy,参考命令:
python3 -m pip install scipy==1.8.1 --only-binary=:all:。该版本已针对Cygwin平台的long double兼容问题打过补丁,不会触发对应编译错误。 - 若必须编译安装指定高版本scipy,手动修改编译配置绕开检查:
- 下载对应版本scipy源码,找到
scipy/_lib/boost/boost/math/tools/promotion.hpp文件,定位到148行附近的long double支持静态断言代码块,直接注释掉该段断言 - 执行编译安装前,添加全局宏定义
BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS,强制Boost数学库仅使用double精度实现特殊函数,绕开平台long double支持不足的检查,再执行编译安装流程即可。
- 下载对应版本scipy源码,找到
内容的提问来源于stack exchange,提问作者Jannis Erhard
相关产品推荐
相关产品推荐

