无法安装numpy:CMake相关报错的问题排查与解决方案咨询
安装Numpy时CMake相关报错的解决办法
问题背景
Python新手安装Numpy时触发编译报错,具体错误日志如下:
Collecting ninja>=1.8.2 Using cached ninja-1.11.1.tar.gz (27 kB) Installing build dependencies: started Installing build dependencies: finished with status 'done' Getting requirements to build wheel: started Getting requirements to build wheel: finished with status 'done' Preparing metadata (pyproject.toml): started Preparing metadata (pyproject.toml): finished with status 'done' Building wheels for collected packages: ninja Building wheel for ninja (pyproject.toml): started Building wheel for ninja (pyproject.toml): finished with status 'error' error: subprocess-exited-with-error Building wheel for ninja (pyproject.toml) did not run successfully. exit code: 1 [9 lines of output] Traceback (most recent call last): File "C:\Users\Lenovo\AppData\Local\Temp\pip-build-env-9e2mdrtx\overlay\lib\python3.10\site-packages\skbuild\setuptools_wrap.py", line 645, in setup cmkr = cmaker.CMaker(cmake_executable) File "C:\Users\Lenovo\AppData\Local\Temp\pip-build-env-9e2mdrtx\overlay\lib\python3.10\site-packages\skbuild\cmaker.py", line 148, in __init__ self.cmake_version = get_cmake_version(self.cmake_executable) File "C:\Users\Lenovo\AppData\Local\Temp\pip-build-env-9e2mdrtx\overlay\lib\python3.10\site-packages\skbuild\cmaker.py", line 105, in get_cmake_version raise SKBuildError(msg) from err Problem with the CMake installation, aborting build. CMake executable is cmake [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for ninja Failed to build ninja ERROR: Could not build wheels for ninja, which is required to install pyproject.toml-based projects [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. error: subprocess-exited-with-error × pip subprocess to install backend dependencies did not run successfully. │ exit code: 1 ╰─> See above for output. note: This error originates from a subprocess, and is likely not a problem with pip.
问题根源
错误日志中的核心提示**Problem with the CMake installation, aborting build. CMake executable is cmake**,说明:
- 系统未安装CMake,或是CMake未添加到系统环境变量,导致pip编译依赖包(此处为ninja)时无法找到CMake执行程序。
- Ninja是Numpy安装依赖的编译工具,而编译Ninja必须用到CMake,因此CMake缺失或不可用直接导致安装流程中断。
解决步骤
方案1:安装预编译Numpy包(新手优先)
跳过编译环节,直接使用官方预编译的二进制包,无需依赖CMake或Ninja:
打开命令提示符/ PowerShell,执行:
pip install numpy --only-binary :all:
方案2:安装并配置CMake(适合需编译其他包的场景)
- 下载对应Windows版本的CMake安装程序(选择带图形安装向导的版本)。
- 运行安装程序时,勾选Add CMake to the system PATH for all users(或当前用户),完成安装。
- 关闭并重新打开命令提示符,执行
cmake --version,若显示版本号则配置成功。 - 重新执行
pip install numpy即可。
方案3:升级pip工具链
旧版本pip可能存在依赖处理逻辑问题,先升级工具再尝试安装:
pip install --upgrade pip setuptools wheel pip install numpy
内容的提问来源于stack exchange,提问作者Hải Đan
相关产品推荐
相关产品推荐

