Python包安装失败:构建wheel依赖项出错求助
解决Python包安装时「Getting requirements to build wheel」失败问题
错误信息
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 ╰─> [28 lines of output] Traceback (most recent call last): File "C:\Users\User\AppData\Local\Programs\Python\Python312\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 353, in <module> main() File "C:\Users\User\AppData\Local\Programs\Python\Python312\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 335, in main json_out['return_val'] = hook(**hook_input['kwargs']) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\User\AppData\Local\Programs\Python\Python312\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 118, in get_requires_for_build_wheel return hook(config_settings) ^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\User\AppData\Local\Temp\pip-build-env-05ydr5uy\overlay\Lib\site-packages\setuptools\build_meta.py", line 355, in get_requires_for_build_wheel return self._get_build_requires(config_settings, requirements=['wheel']) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\User\AppData\Local\Temp\pip-build-env-05ydr5uy\overlay\Lib\site-packages\setuptools\build_meta.py", line 325, in _get_build_requires self.run_setup() File "C:\Users\User\AppData\Local\Temp\pip-build-env-05ydr5uy\overlay\Lib\site-packages\setuptools\build_meta.py", line 507, in run_setup super(_BuildMetaLegacyBackend, self).run_setup(setup_script=setup_script) File "C:\Users\User\AppData\Local\Temp\pip-build-env-05ydr5uy\overlay\Lib\site-packages\setuptools\build_meta.py", line 341, in run_setup exec(code, locals()) File "<string>", line 47, in <module> File "C:\Users\User\AppData\Local\Programs\Python\Python312\Lib\subprocess.py", line 389, in call with Popen(*popenargs, **kwargs) as p: ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\User\AppData\Local\Programs\Python\Python312\Lib\subprocess.py", line 1026, in __init__ self._execute_child(args, executable, preexec_fn, close_fds, File "C:\Users\User\AppData\Local\Programs\Python\Python312\Lib\subprocess.py", line 1538, in _execute_child hp, ht, pid, tid = _winapi.CreateProcess(executable, args, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FileNotFoundError: [WinError 2] The system cannot find the file specified [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. error: subprocess-exited-with-error
解决方案
从错误栈看,问题出在包的setup.py第47行调用外部程序时找不到文件,结合Windows + Python3.12环境,按以下步骤排查:
安装Windows编译工具链
Windows下编译Python扩展包需要Visual Studio构建工具,打开Visual Studio Installer,选择「Desktop development with C++」,勾选:- MSVC v143 - VS 2022 C++ x64/x86 build tools
- Windows对应版本的SDK(比如Windows 11 SDK)
安装完成后重启终端再尝试安装。
更新pip、setuptools、wheel到最新版
执行命令:python -m pip install --upgrade pip setuptools wheel优先安装预编译wheel包
如果目标包有预编译的Windows wheel,直接跳过编译步骤:pip install --only-binary :all: [你的包名称]替换
[你的包名称]为你要安装的包。检查包的Python版本兼容性
部分老包尚未适配Python3.12,去包的PyPI页面或GitHub仓库查看支持的Python版本,若不兼容,可降级到Python3.11再尝试安装。定位缺失的外部程序
如果是公开包,找到其源码中的setup.py第47行,查看调用的程序(比如git、gcc等),确保该程序已安装并添加到系统PATH中。
内容的提问来源于stack exchange,提问作者user22777142
相关产品推荐
相关产品推荐

