无法安装Python库,提示subprocess-exited-with-error错误求助
问题
无法安装任何Python库,执行pip install时总是提示subprocess-exited-with-error错误,以安装numpy为例的完整报错如下:
PS D:\Learning\py\python basics\> pip install numpy Collecting numpy Downloading numpy-1.26.0.tar.gz (15.6 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 15.6/15.6 MB 2.4 MB/s eta 0:00:00 Installing build dependencies ... done Getting requirements to build wheel ... done Installing backend dependencies ... error error: subprocess-exited-with-error × pip subprocess to install backend dependencies did not run successfully. │ exit code: 1 ╰─> [37 lines of output] Collecting ninja>=1.8.2 Downloading ninja-1.11.1.1.tar.gz (132 kB) -------------------------------------- 132.4/132.4 kB 1.1 MB/s eta 0:00:00 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 [13 lines of output] C:\Users\Abaan\AppData\Local\Temp\pip-build-env-nxqms1f9\overlay\lib\python3.10\site-packages\setuptools_scm\git.py:308: UserWarning: git archive did not support describe output warnings.warn("git archive did not support describe output") C:\Users\Abaan\AppData\Local\Temp\pip-build-env-nxqms1f9\overlay\lib\python3.10\site-packages\setuptools_scm\git.py:327: UserWarning: unprocessed git archival found (no export subst applied) warnings.warn("unprocessed git archival found (no export subst applied)") Traceback (most recent call last): File "C:\Users\Abaan\AppData\Local\Temp\pip-build-env-nxqms1f9\overlay\lib\python3.10\site-packages\skbuild\setuptools_wrap.py", line 645, in setup cmkr = cmaker.CMaker(cmake_executable) File "C:\Users\Abaan\AppData\Local\Temp\pip-build-env-nxqms1f9\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\Abaan\AppData\Local\Temp\pip-build-env-nxqms1f9\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.
已尝试的操作:
- 升级pip、setuptools,问题依旧
- 检查系统环境变量,确认无异常
- 以管理员身份运行安装命令,无效
- 检查系统PATH变量,未找到有效解决点
- 确认网络连接稳定,安装过程无中断
- 在新虚拟环境中尝试安装,报错相同
已知环境:Pip版本23.2.1,Python版本3.10.12。错误指向CMake安装问题,但已确认CMake可执行文件配置正确,近期无系统更新或变更。
解决建议
1. 验证CMake的实际可用性
手动验证CMake是否能正常调用:
- 打开命令提示符,执行
cmake --version,确认能正常返回版本信息,无报错 - 如果命令执行失败,重新安装CMake并勾选"Add CMake to system PATH"选项,安装后重启终端再试
2. 跳过源码编译,直接安装预编译轮子
强制pip使用预编译包,避免编译依赖:
pip install numpy --only-binary :all:
若仍失败,指定兼容Python3.10的稳定版本:
pip install numpy==1.25.2 --only-binary :all:
3. 手动安装ninja依赖
针对ninja编译失败问题,直接安装预编译版本:
- 下载对应系统的ninja预编译二进制文件(Windows选.exe版本)
- 将ninja.exe所在路径添加到系统PATH
- 重启终端后再执行
pip install numpy
4. 降级pip版本
新版本pip可能存在兼容性问题,尝试降级到稳定版本:
pip install pip==22.3.1
之后再尝试安装库
5. 修复Python安装
重新修复Python安装,确保组件完整:
- 打开Python安装程序,选择"Modify"
- 勾选"Add Python to PATH",点击"Repair"完成后重启终端
内容的提问来源于stack exchange,提问作者Abaan Tamboli
相关产品推荐
相关产品推荐

