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

使用pip安装Selenium时遭遇构建Wheel依赖错误的求助

安装Selenium时Getting requirements to build wheel报错解决

问题现象

  • 运行测试代码提示ModuleNotFoundError: No module named 'selenium'
  • 执行安装命令时,在Getting requirements to build wheel步骤失败,核心错误为:
    distutils.errors.DistutilsPlatformError: --plat-name must be one of ('win32', 'win-amd64', 'win-arm32', 'win-arm64')
    

完整错误日志:

PS C:\Users\Oisin\repositories\Scraper> python -m pip install selenium
Collecting selenium
  Using cached selenium-4.21.0-py3-none-any.whl.metadata (6.9 kB)
Requirement already satisfied: urllib3<3,>=1.26 in c:\msys64\mingw64\lib\python3.10\site-packages (from urllib3[socks]<3,>=1.26->selenium) (2.2.1)
Collecting trio~=0.17 (from selenium)
  Using cached trio-0.25.1-py3-none-any.whl.metadata (8.7 kB)
Collecting trio-websocket~=0.9 (from selenium)
  Using cached trio_websocket-0.11.1-py3-none-any.whl.metadata (4.7 kB)
Requirement already satisfied: certifi>=2021.10.8 in c:\msys64\mingw64\lib\python3.10\site-packages (from selenium) (2024.2.2)
Collecting typing_extensions>=4.9.0 (from selenium)
  Using cached typing_extensions-4.11.0-py3-none-any.whl.metadata (3.0 kB)
Collecting attrs>=23.2.0 (from trio~=0.17->selenium)
  Using cached attrs-23.2.0-py3-none-any.whl.metadata (9.5 kB)
Collecting sortedcontainers (from trio~=0.17->selenium)
  Using cached sortedcontainers-2.4.0-py2.py3-none-any.whl.metadata (10 kB)
Requirement already satisfied: idna in c:\msys64\mingw64\lib\python3.10\site-packages (from trio~=0.17->selenium) (3.7)
Collecting outcome (from trio~=0.17->selenium)
  Using cached outcome-1.3.0.post0-py2.py3-none-any.whl.metadata (2.6 kB)
Collecting sniffio>=1.3.0 (from trio~=0.17->selenium)
  Using cached sniffio-1.3.1-py3-none-any.whl.metadata (3.9 kB)
Collecting cffi>=1.14 (from trio~=0.17->selenium)
  Using cached cffi-1.16.0.tar.gz (512 kB)
  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
  ╰─> [24 lines of output]
      Traceback (most recent call last):
        File "C:\msys64\mingw64\lib\python3.10\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 353, in <module>
          main()
        File "C:\msys64\mingw64\lib\python3.10\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:\msys64\mingw64\lib\python3.10\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\Oisin\AppData\Local\Temp\pip-build-env-f8yun7ic\overlay\lib\python3.10\site-packages\setuptools\build_meta.py", line 325, in get_requires_for_build_wheel
          return self._get_build_requires(config_settings, requirements=['wheel'])
        File "C:\Users\Oisin\AppData\Local\Temp\pip-build-env-f8yun7ic\overlay\lib\python3.10\site-packages\setuptools\build_meta.py", line 295, in _get_build_requires
          self.run_setup()
        File "C:\Users\Oisin\AppData\Local\Temp\pip-build-env-f8yun7ic\overlay\lib\python3.10\site-packages\setuptools\build_meta.py", line 311, in run_setup
          exec(code, locals())
        File "<string>", line 126, in <module>
        File "<string>", line 105, in uses_msvc
        File "C:\Users\Oisin\AppData\Local\Temp\pip-build-env-f8yun7ic\overlay\lib\python3.10\site-packages\setuptools\_distutils\command\config.py", line 220, in try_compile
          self._compile(body, headers, include_dirs, lang)
        File "C:\Users\Oisin\AppData\Local\Temp\pip-build-env-f8yun7ic\overlay\lib\python3.10\site-packages\setuptools\_distutils\command\config.py", line 132, in _compile
          self.compiler.compile([src], include_dirs=include_dirs)
        File "C:\Users\Oisin\AppData\Local\Temp\pip-build-env-f8yun7ic\overlay\lib\python3.10\site-packages\setuptools\_distutils\_msvccompiler.py", line 343, in compile
          self.initialize()
        File "C:\Users\Oisin\AppData\Local\Temp\pip-build-env-f8yun7ic\overlay\lib\python3.10\site-packages\setuptools\_distutils\_msvccompiler.py", line 246, in initialize
          raise DistutilsPlatformError(
      distutils.errors.DistutilsPlatformError: --plat-name must be one of ('win32', 'win-amd64', 'win-arm32', 'win-arm64')
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× Getting requirements to build wheel 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.
PS C:\Users\Oisin\repositories\Scraper>

已尝试操作

  • 检查临时目录C:\Users\Oisin\AppData\Local\Temp\pip-build-env-f8yun7ic\,该目录不存在,仅找到类似目录pip-uninstall-tk4rop8y
  • 尝试多种安装命令:pip install selenium、python3 -m pip install selenium、pip3 install selenium
  • 执行python.exe -m pip install --upgrade pip更新pip,问题未解决

环境信息

python --version

Python 3.10.11

python -m pip --version

pip 24.0 from C:\msys64\mingw64\lib\python3.10\site-packages\pip (python 3.10)

解决方案

1. 手动指定平台名称安装

执行安装命令时添加--plat-name参数,适配你的系统架构:

# 64位Windows系统
python -m pip install selenium --plat-name win-amd64

# 32位Windows系统
python -m pip install selenium --plat-name win32

2. 直接安装预编译wheel包

下载对应版本的selenium通用wheel包(无需编译),本地安装:

# 替换为实际下载的wheel包路径
python -m pip install selenium-4.21.0-py3-none-any.whl

3. 设置环境变量修复平台识别

在PowerShell中临时设置环境变量后再安装:

$env:DISTUTILS_USE_SDK=1
python -m pip install selenium

4. 安装MSYS2编译工具链

如果依赖需要编译,先安装MSYS2的编译工具和系统级cffi:

# 在MSYS2终端执行
pacman -S mingw-w64-x86_64-gcc mingw-w64-x86_64-python-cffi

安装完成后再执行selenium安装命令。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.23 18:52:34