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

Python3.8环境下PyQt5安装失败求助:报错排查

PyQt5安装失败排查与解决(Python 3.8)

问题场景

使用Python 3.8,执行pip3 install pyqt5安装PyQt5时失败,报错信息如下:

Collecting PyQt5
  Using cached https://files.pythonhosted.org/packages/4d/5d/b8b6e26956ec113ad3f566e02abd12ac3a56b103fcc7e0735e27ee4a1df3/PyQt5-5.15.10.tar.gz
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... error
    ERROR: Command errored out with exit status 1:
     command: 'c:\users\stard\appdata\local\programs\python\python38\python.exe' 'c:\users\stard\appdata\local\programs\python\python38\lib\site-packages\pip\_vendor\pep517\_in_process.py' prepare_metadata_for_build_wheel 'C:\Users\stard\AppData\Local\Temp\tmpo8hmzyy0'
         cwd: C:\Users\stard\AppData\Local\Temp\pip-install-m9pon6sv\PyQt5
    Complete output (32 lines):
    pyproject.toml: line 7: using '[tool.sip.metadata]' to specify the project metadata is deprecated and will be removed in SIP v7.0.0, use '[project]' instead
    Traceback (most recent call last):
      File "c:\users\stard\appdata\local\programs\python\python38\lib\site-packages\pip\_vendor\pep517\_in_process.py", line 64, in prepare_metadata_for_build_wheel
        hook = backend.prepare_metadata_for_build_wheel
    AttributeError: module 'sipbuild.api' has no attribute 'prepare_metadata_for_build_wheel'

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "c:\users\stard\appdata\local\programs\python\python38\lib\site-packages\pip\_vendor\pep517\_in_process.py", line 207, in <module>
        main()
      File "c:\users\stard\appdata\local\programs\python\python38\lib\site-packages\pip\_vendor\pep517\_in_process.py", line 197, in main
        json_out['return_val'] = hook(**hook_input['kwargs'])
      File "c:\users\stard\appdata\local\programs\python\python38\lib\site-packages\pip\_vendor\pep517\_in_process.py", line 66, in prepare_metadata_for_build_wheel
        return _get_wheel_metadata_from_wheel(backend, metadata_directory,
      File "c:\users\stard\appdata\local\programs\python\python38\lib\site-packages\pip\_vendor\pep517\_in_process.py", line 95, in _get_wheel_metadata_from_wheel
        whl_basename = backend.build_wheel(metadata_directory, config_settings)
      File "C:\Users\stard\AppData\Local\Temp\pip-build-env-l5m4_3ce\overlay\Lib\site-packages\sipbuild\api.py", line 46, in build_wheel
        project = AbstractProject.bootstrap('wheel',
      File "C:\Users\stard\AppData\Local\Temp\pip-build-env-l5m4_3ce\overlay\Lib\site-packages\sipbuild\abstract_project.py", line 87, in bootstrap
        project.setup(pyproject, tool, tool_description)
      File "C:\Users\stard\AppData\Local\Temp\pip-build-env-l5m4_3ce\overlay\Lib\site-packages\sipbuild\project.py", line 587, in setup
        self.apply_user_defaults(tool)
      File "project.py", line 68, in apply_user_defaults
        super().apply_user_defaults(tool)
      File "C:\Users\stard\AppData\Local\Temp\pip-build-env-l5m4_3ce\overlay\Lib\site-packages\pyqtbuild\project.py", line 70, in apply_user_defaults
        super().apply_user_defaults(tool)
      File "C:\Users\stard\AppData\Local\Temp\pip-build-env-l5m4_3ce\overlay\Lib\site-packages\sipbuild\project.py", line 237, in apply_user_defaults
        self.builder.apply_user_defaults(tool)
      File "C:\Users\stard\AppData\Local\Temp\pip-build-env-l5m4_3ce\overlay\Lib\site-packages\pyqtbuild\builder.py", line 69, in apply_user_defaults
        raise PyProjectOptionException('qmake',
    sipbuild.pyproject.PyProjectOptionException
    ----------------------------------------
ERROR: Command errored out with exit status 1: 'c:\users\stard\appdata\local\programs\python\python38\python.exe' 'c:\users\stard\appdata\local\programs\python\python38\lib\site-packages\pip\_vendor\pep517\_in_process.py' prepare_metadata_for_build_wheel 'C:\Users\stard\AppData\Local\Temp\tmpo8hmzyy0' Check the logs for full command output.

原因分析

  1. 新版PyQt5已停止对Python3.8的支持,直接安装会触发源码编译,而编译依赖的Qt环境(qmake)未配置。
  2. sip版本不兼容,报错提示sipbuild.api缺少指定属性,是因为新版本sip与旧版PyQt5或Python3.8不匹配。

解决步骤

1. 安装兼容Python3.8的PyQt5版本

指定Python3.8支持的最后几个PyQt5版本之一,比如5.15.4,避免源码编译:

pip3 install pyqt5==5.15.4

2. 适配sip版本

先卸载现有sip,安装与PyQt5 5.15.4兼容的sip版本:

pip3 uninstall -y sip
pip3 install sip==6.6.2

3. 加速安装(可选)

如果下载慢,使用国内PyPI镜像:

pip3 install pyqt5==5.15.4 sip==6.6.2 -i https://pypi.tuna.tsinghua.edu.cn/simple

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.03 20:25:20