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

安装Python3.11的Yt-Dlp模块时Brotli编译失败求助

问题描述

尝试为Python 3.11安装yt-dlp模块时,出现Brotli编译失败的错误,具体错误信息如下:

Building wheels for collected packages: brotli
  Building wheel for brotli (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [20 lines of output]
      C:\Users\igor\AppData\Local\Programs\Python\Python311\Lib\site-packages\setuptools\dist.py:771: UserWarning: Usage of dash-separated 'build-base' will not be supported in future versions. Please use the underscore name 'build_base' instead
        warnings.warn(
      running bdist_wheel
      running build
      running build_py
      creating bin
      creating bin\lib.win-amd64-cpython-311
      copying python\brotli.py -> bin\lib.win-amd64-cpython-311
      running build_ext
      building '_brotli' extension
      creating bin\temp.win-amd64-cpython-311
      creating bin\temp.win-amd64-cpython-311\Release
      creating bin\temp.win-amd64-cpython-311\Release\c
      creating bin\temp.win-amd64-cpython-311\Release\c\common
      creating bin\temp.win-amd64-cpython-311\Release\c\dec
      creating bin\temp.win-amd64-cpython-311\Release\c\enc
      "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.34.31933\bin\HostX86\x64\cl.exe" /c /nologo /O2 /W3 /GL /DNDEBUG /MD -Ic/include -IC:\Users\igor\AppData\Local\Programs\Python\Python311\include -IC:\Users\igor\AppData\Local\Programs\Python\Python311\Include "-IC:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.34.31933\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\VS\include" /Tcc/common/constants.c /Fobin\temp.win-amd64-cpython-311\Release\c/common/constants.obj
      constants.c
      C:\Users\igor\AppData\Local\Temp\pip-install-cplthpdp\brotli_bec0f5da12d0434ea2253cdadf0efb64\c\common\./platform.h(26): fatal error C1083: Não é possível abrir arquivo incluir: 'string.h': No such file or directory
      error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\VC\\Tools\\MSVC\\14.34.31933\\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 brotli
  Running setup.py clean for brotli
Failed to build brotli
Installing collected packages: brotli, websockets, yt-dlp
  Running setup.py install for brotli ... error
  error: subprocess-exited-with-error

  × Running setup.py install for brotli did not run successfully.
  │ exit code: 1
  ╰─> [22 lines of output]
      C:\Users\igor\AppData\Local\Programs\Python\Python311\Lib\site-packages\setuptools\dist.py:771: UserWarning: Usage of dash-separated 'build-base' will not be supported in future versions. Please use the underscore name 'build_base' instead
        warnings.warn(
      running install
      C:\Users\igor\AppData\Local\Programs\Python\Python311\Lib\site-packages\setuptools\command\install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
        warnings.warn(
      running build
      running build_py
      creating bin
      creating bin\lib.win-amd64-cpython-311
      copying python\brotli.py -> bin\lib.win-amd64-cpython-311
      running build_ext
      building '_brotli' extension
      creating bin\temp.win-amd64-cpython-311
      creating bin\temp.win-amd64-cpython-311\Release
      creating bin\temp.win-amd64-cpython-311\Release\c
      creating bin\temp.win-amd64-cpython-311\Release\c\common
      creating bin\temp.win-amd64-cpython-311\Release\c\dec
      creating bin\temp.win-amd64-cpython-311\Release\c\enc
      "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.34.31933\bin\HostX86\x64\cl.exe" /c /nologo /O2 /W3 /GL /DNDEBUG /MD -Ic/include -IC:\Users\igor\AppData\Local\Programs\Python\Python311\include -IC:\Users\igor\AppData\Local\Programs\Python\Python311\Include "-IC:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.34.31933\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\VS\include" /Tcc/common/constants.c /Fobin\temp.win-amd64-cpython-311\Release\c/common/constants.obj
      constants.c
      C:\Users\igor\AppData\Local\Temp\pip-install-cplthpdp\brotli_bec0f5da12d0434ea2253cdadf0efb64\c\common\./platform.h(26): fatal error C1083: Não é possível abrir arquivo incluir: 'string.h': No such file or directory
      error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\VC\\Tools\\MSVC\\14.34.31933\\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: legacy-install-failure

已尝试卸载并重装C++ Build Tools、重启电脑、单独安装Brotli包,但问题仍未解决。


解决方案

核心原因

错误提示找不到string.h,这是C标准库的核心头文件,说明MSVC Build Tools缺少Windows SDK的标准库组件,或者环境变量未正确配置,导致编译器无法定位系统头文件。

1. 补全Windows SDK组件

打开Visual Studio Installer,找到已安装的Visual Studio Build Tools 2022,点击「修改」:

  • 勾选对应你系统版本的Windows SDK(比如Windows 10 SDK或Windows 11 SDK)
  • 确保「SDK中的C++工具」选项被勾选
  • 完成安装后重启电脑

2. 使用MSVC命令行环境安装

以管理员身份启动「x64 Native Tools Command Prompt for VS 2022」,这个环境已经自动配置好所有MSVC编译所需的环境变量,直接在该窗口执行:

pip install yt-dlp

3. 跳过编译,安装预编译Brotli包

如果编译问题仍存在,直接安装官方预编译的Brotli二进制包,避免本地编译:

pip install --only-binary :all: brotli

安装完成后再执行yt-dlp的安装命令:

pip install yt-dlp

4. 验证Python架构兼容性

确保你的Python 3.11是64位版本(和Build Tools的x64架构匹配),如果是32位Python,需要在Visual Studio Installer中勾选32位的MSVC组件和对应版本的Windows SDK。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.12 19:11:31