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

安装pyspectra时无法识别已安装numpy的问题求助

问题描述

在Windows10系统的Python3.12.5全新虚拟环境(pip24.2)中,尝试安装pyspectra(用于分析近红外NIR光谱、读取SPC格式文件)时失败,报错信息为Getting requirements to build wheel did not run successfully,回溯最后一行显示ModuleNotFoundError: No module named 'numpy'。

已手动安装numpy2.1.2,且在同一虚拟环境中验证import numpy as np可正常运行,但安装pyspectra时仍提示找不到numpy。

附完整命令行操作过程:

# 创建并激活虚拟环境
C:\user\...\Desktop>python -m venv venv
C:\user\...\Desktop>venv\scripts\activate

# 安装numpy
(venv) C:\user\...\Desktop>py -m pip install numpy

# 安装pyspectra
(venv) C:\user\...\Desktop>py -m pip install pyspectra
Collecting pyspectra
  Using cached pyspectra-0.0.1.2-py3-none-any.whl.metadata (12 kB)
Requirement already satisfied: numpy in c:\users\...\venv\lib\site-packages (from pyspectra) (2.1.2)
Collecting pandas (from pyspectra)
  Using cached pandas-2.2.3-cp312-cp312-win_amd64.whl.metadata (19 kB)
Collecting spc-spectra (from pyspectra)
  Using cached spc_spectra-0.4.0.tar.gz (8.6 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... error
  error: subprocess-exited-with-error

  × Getting requirements to build wheel did not run successfully.
  │ exit code: 1
  ╰─> [24 lines of output]
      Traceback (most recent call last):
        [...]
        File "C:\Users\...\AppData\Local\Temp\pip-install-v_qa0rxl\spc-spectra_a351371d52ef45edbd585ef2843e5c1e\spc_spectra\spc.py", line 10, in <module>
          import numpy as np
      ModuleNotFoundError: No module named 'numpy'
      [end of output]
原因分析与解决办法

原因

问题根源在于pyspectra依赖的spc-spectra 0.4.0包:

  1. 该包的构建脚本未正确声明对numpy的依赖,导致在构建wheel阶段无法识别虚拟环境中已安装的numpy;
  2. numpy2.x属于大版本更新,spc-spectra 0.4.0未适配该版本,存在兼容性问题。

解决办法

方法1:降级numpy到兼容版本

将numpy降级到1.x系列的稳定版本(如1.26.4),再安装pyspectra:

# 卸载当前numpy版本
pip uninstall -y numpy
# 安装兼容的旧版本
pip install numpy==1.26.4
# 重新安装pyspectra
pip install pyspectra

方法2:升级spc-spectra到最新版

检查spc-spectra是否有修复该问题的更新版本,先升级该依赖再安装pyspectra:

pip install spc-spectra --upgrade
pip install pyspectra

方法3:更换替代库

如果上述方法无效,可以使用其他支持SPC格式的光谱分析库,比如spc或pyspc,这些库的兼容性更稳定。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.17 03:01:07