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

Ubuntu 24.04下PyPy安装Scipy失败问题求助

在PyPy环境中安装Scipy时遇到段错误的解决思路

问题背景

使用的环境信息:

Python 3.8.13 (7.3.9+dfsg-1ubuntu0.1, Nov 15 2022, 06:22:50)
[PyPy 7.3.9 with GCC 11.3.0]

操作系统为Ubuntu 24.04,已执行以下命令完成基础安装:

  • sudo apt install pypy3
  • sudo apt install gfortran

执行pypy -m pip install scipy时失败,核心错误为多次出现Segmentation fault (core dumped),具体失败环节如下:

[263/1619] Generating scipy/special/_data_gsl with a custom command
      FAILED: scipy/special/gsl.npz
      /usr2/repositories/DSP/dspos/RoomResponseRef/source/python/some_env/bin/pypy3 ../../scipy/special/utils/makenpz.py --use-timestamp gsl -o scipy/special
      Segmentation fault (core dumped)
      [264/1619] Compiling C++ object scipy/special/_ufuncs_cxx.pypy38-pp73-x86_64-linux-gnu.so.p/ellint_carlson_wrap.cxx.o
      [265/1619] Generating scipy/special/_data_boost with a custom command
      FAILED: scipy/special/boost.npz
      /usr2/repositories/DSP/dspos/RoomResponseRef/source/python/some_env/bin/pypy3 ../../scipy/special/utils/makenpz.py --use-timestamp boost -o scipy/special
      Segmentation fault (core dumped)
      [266/1619] Generating scipy/linalg/flinalg_module with a custom command
      [267/1619] Generating scipy/special/_data_local with a custom command
      FAILED: scipy/special/local.npz
      /usr2/repositories/DSP/dspos/RoomResponseRef/source/python/some_env/bin/pypy3 ../../scipy/special/utils/makenpz.py --use-timestamp local -o scipy/special
      Segmentation fault (core dumped)
      [268/1619] Generating 'scipy/special/_comb.pypy38-pp73-x86_64-linux-gnu.so.p/_comb.c'
      [269/1619] Generating 'scipy/_lib/_ccallback_c.pypy38-pp73-x86_64-linux-gnu.so.p/_ccallback_c.c'
      [270/1619] Generating 'scipy/_lib/messagestream.pypy38-pp73-x86_64-linux-gnu.so.p/messagestream.c'
      [271/1619] Generating scipy/linalg/interpolative_module with a custom command
      [272/1619] Compiling Fortran object scipy/special/libspecfun.a.p/specfun_specfun.f.o
      [273/1619] Generating 'scipy/special/_ufuncs_cxx.pypy38-pp73-x86_64-linux-gnu.so.p/_ufuncs_cxx.cpp'
      [274/1619] Generating scipy/linalg/fblas_module with a custom command
      [275/1619] Generating 'scipy/special/_ellip_harm_2.pypy38-pp73-x86_64-linux-gnu.so.p/_ellip_harm_2.c'
      [276/1619] Generating 'scipy/special/_test_internal.pypy38-pp73-x86_64-linux-gnu.so.p/_test_internal.c'
      [277/1619] Generating 'scipy/stats/_sobol.pypy38-pp73-x86_64-linux-gnu.so.p/_sobol.c'
      [278/1619] Generating scipy/linalg/flapack_module with a custom command
      [279/1619] Generating 'scipy/special/_ufuncs.pypy38-pp73-x86_64-linux-gnu.so.p/_ufuncs.c'
      [280/1619] Generating 'scipy/special/cython_special.pypy38-pp73-x86_64-linux-gnu.so.p/cython_special.c'
      ninja: build stopped: subcommand failed.
      INFO: autodetecting backend as ninja
      INFO: calculating backend command to run: /usr/bin/ninja
      + meson setup --prefix=/usr /tmp/pip-install-ecigaz4z/scipy_bae3c05728ed48d0a94e36cf7aeb04ac /tmp/pip-install-ecigaz4z/scipy_bae3c05728ed48d0a94e36cf7aeb04ac/.mesonpy-hvxyf1qr/build --native-file=/tmp/pip-install-ecigaz4z/scipy_bae3c05728ed48d0a94e36cf7aeb04ac/.mesonpy-native-file.ini -Ddebug=false -Doptimization=2
      + meson compile
      [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.

解决思路

  • 升级PyPy版本:当前使用的PyPy 7.3.9是2022年的版本,Ubuntu 24.04软件源可能有更新版本,执行sudo apt update && sudo apt upgrade pypy3尝试升级;若源中版本仍旧,可手动下载安装官方最新稳定版,新版本通常会修复旧版兼容性与段错误问题。

  • 安装预编译Scipy包:避免源码编译,执行pip install scipy --only-binary :all:强制安装二进制包;若pip找不到对应PyPy的包,可尝试指定适配旧PyPy的Scipy版本,比如pypy -m pip install scipy==1.10.1。

  • 补全编译依赖:Scipy编译除gfortran外,还需libopenblas-dev、liblapack-dev、cython3、meson、ninja-build等依赖,执行sudo apt install libopenblas-dev liblapack-dev cython3 meson ninja-build安装后,重新尝试编译安装。

  • 调试出错脚本:进入Scipy临时安装目录(类似/tmp/pip-install-ecigaz4z/scipy_bae3c05728ed48d0a94e36cf7aeb04ac),手动运行出错的脚本:pypy3 scipy/special/utils/makenpz.py --use-timestamp gsl -o scipy/special,用gdb调试段错误:gdb pypy3 --args scipy/special/utils/makenpz.py --use-timestamp gsl -o scipy/special,输入run启动,崩溃后输入bt查看调用栈定位问题。

  • 创建干净虚拟环境:当前环境可能存在冲突,创建新PyPy虚拟环境:pypy3 -m venv new_env,激活后source new_env/bin/activate再尝试安装Scipy,排除环境干扰。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.20 12:35:04