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

Python库pesq编译Wheel失败:找不到'math.h'文件报错

安装pesq库时构建Wheel失败,提示找不到math.h的解决办法

错误日志

Collecting pesq
  Using cached pesq-0.0.4.tar.gz (38 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Installing backend dependencies ... done
  Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: pesq
  Building wheel for pesq (pyproject.toml) ... error
  error: subprocess-exited-with-error

  × Building wheel for pesq (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [29 lines of output]
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build\lib.win-amd64-cpython-38
      creating build\lib.win-amd64-cpython-38\pesq
      copying pesq\_pesq.py -> build\lib.win-amd64-cpython-38\pesq
      copying pesq\__init__.py -> build\lib.win-amd64-cpython-38\pesq
      copying pesq\cypesq.pyx -> build\lib.win-amd64-cpython-38\pesq
      copying pesq\dsp.h -> build\lib.win-amd64-cpython-38\pesq
      copying pesq\pesq.h -> build\lib.win-amd64-cpython-38\pesq
      copying pesq\pesqio.h -> build\lib.win-amd64-cpython-38\pesq
      copying pesq\pesqmain.h -> build\lib.win-amd64-cpython-38\pesq
      copying pesq\pesqpar.h -> build\lib.win-amd64-cpython-38\pesq
      copying pesq\dsp.c -> build\lib.win-amd64-cpython-38\pesq
      copying pesq\pesqdsp.c -> build\lib.win-amd64-cpython-38\pesq
      copying pesq\pesqmod.c -> build\lib.win-amd64-cpython-38\pesq
      running build_ext
      cythoning pesq/cypesq.pyx to pesq\cypesq.c
      building 'cypesq' extension
      creating build\temp.win-amd64-cpython-38
      creating build\temp.win-amd64-cpython-38\Release
      creating build\temp.win-amd64-cpython-38\Release\pesq
      "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\bin\HostX86\x64\cl.exe" /c /nologo /O2 /W3 /GL /DNDEBUG /MD -Ipesq -IC:\Users\aliemir\AppData\Local\Temp\pip-build-env-l1h82fpj\normal\Lib\site-packages\numpy\core\include -IC:\Users\aliemir\AppData\Local\Temp\pip-build-env-l1h82fpj\normal\Lib\site-packages\numpy\core\include -IC:\Users\aliemir\anaconda3\envs\tts-fast\include -IC:\Users\aliemir\anaconda3\envs\tts-fast\Include "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include" /Tcpesq/dsp.c /Fobuild\temp.win-amd64-cpython-38\Release\pesq/dsp.obj
      dsp.c
      pesq/dsp.c(105): fatal error C1083: 无法找到文件: 'math.h': No such file or directory
      C:\Users\aliemir\AppData\Local\Temp\pip-build-env-l1h82fpj\normal\Lib\site-packages\Cython\Compiler\Main.py:369: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: C:\Users\aliemir\AppData\Local\Temp\pip-install-uwz3mea7\pesq_54c683f7e04241abbcd6048c16a56a0e\pesq\cypesq.pyx
        tree = Parsing.p_module(s, pxd, full_module_name)
      error: command 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\bin\HostX86\x64\cl.exe' failed with exit code 2
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for pesq
Failed to build pesq
ERROR: Could not build wheels for pesq, which is required to install pyproject.toml-based projects

已尝试操作

  • 升级pip、wheel和setuptools:python -m pip install -U pip setuptools
  • 在conda环境内完成上述工具升级
  • 使用pip install --use-pep517 pesq命令安装

问题分析

错误核心是MSVC编译器找不到math.h,且系统优先调用了MSVC的cl.exe而非已安装的MinGW gcc。math.h属于Windows SDK组件,要么修复MSVC的SDK配置,要么强制pip使用MinGW编译。

解决办法

方案一:修复MSVC的Windows SDK配置

  1. 打开Visual Studio Installer,选择已安装的VS2019 Community版本,点击「修改」
  2. 在「单个组件」中,找到对应系统版本的Windows SDK(如Windows 10 SDK 10.0.19041.0或更高),勾选后点击「修改」完成安装
  3. 打开VS的x64 Native Tools Command Prompt,激活conda环境后执行pip install pesq

方案二:强制使用MinGW gcc编译

  1. 将MinGW的bin目录(如C:\MinGW\bin)添加到系统环境变量PATH最前端,避免被MSVC路径覆盖
  2. 在conda环境中安装mingw-w64工具链:conda install -c conda-forge mingw-w64
  3. 在当前用户目录或项目目录创建/修改setup.cfg文件,添加以下内容:
[build]
compiler = mingw32
  1. 执行pip install pesq --no-build-isolation,强制使用MinGW编译

方案三:安装预编译wheel包

直接下载对应Python版本和系统架构的预编译wheel包,本地安装:

  • 找到匹配版本的wheel文件(如Python3.8 + win-amd64的pesq-0.0.4-cp38-cp38-win_amd64.whl)
  • 执行pip install 本地文件路径\pesq-xxx.whl

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.23 19:24:57