Windows系统无法直接用uv安装pyqt5,但可以用uv pip安装

诸神缄默不语-个人技术博文与视频目录

1. 问题

问题:
执行uv add pyqt5时安装失败:

Resolved 144 packages in 6.34s
error: Distribution `pyqt5-qt5==5.15.18 @ registry+https://pypi.org/simple` can't be installed because it doesn't have a source distribution or wheel for the current platform

hint: You're on Windows (`win_amd64`), but `pyqt5-qt5` (v5.15.18) only has wheels for the following platforms: `manylinux2014_x86_64`, `macosx_10_13_x86_64`, `macosx_11_0_arm64`; consider adding your platform to `tool.uv.required-environments` to ensure uv resolves to a version with compatible wheels

如果在pyproject.toml中直接写入pyqt5的话,执行uv sync时会这么报错:

Resolved 145 packages in 1.78s
  × Failed to build `pyqt5==5.15.2`
  ├─▶ The build backend returned an error                                           
  ╰─▶ Call to `sipbuild.api.build_wheel` failed (exit code: 1)

      [stderr]
      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 "<string>", line 11, in <module>
          wheel_filename =
      backend.build_wheel("D:\\all_applications\\foruv\\foruvcache\\builds-v0\\.tmpdm8CqW",
      {}, None)
        File
      "D:\all_applications\foruv\foruvcache\builds-v0\.tmpywcL19\Lib\site-packages\sipbuild\api.py",
      line 28, in build_wheel
          project = AbstractProject.bootstrap('wheel',
                  arguments=_convert_config_settings(config_settings))
        File
      "D:\all_applications\foruv\foruvcache\builds-v0\.tmpywcL19\Lib\site-packages\sipbuild\abstract_project.py",
      line 74, in bootstrap
          project.setup(pyproject, tool, tool_description)
          ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File
      "D:\all_applications\foruv\foruvcache\builds-v0\.tmpywcL19\Lib\site-packages\sipbuild\project.py",
      line 661, in setup
          self.apply_user_defaults(tool)
          ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
        File
      "D:\all_applications\foruv\foruvcache\sdists-v9\pypi\pyqt5\5.15.2\DCnXDNUwgyaPDx3Z6cidl\src\project.py",
      line 63, in apply_user_defaults
          super().apply_user_defaults(tool)
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
        File
      "D:\all_applications\foruv\foruvcache\builds-v0\.tmpywcL19\Lib\site-packages\pyqtbuild\project.py",
      line 51, in apply_user_defaults
          super().apply_user_defaults(tool)
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
        File
      "D:\all_applications\foruv\foruvcache\builds-v0\.tmpywcL19\Lib\site-packages\sipbuild\project.py",
      line 248, in apply_user_defaults
          self.builder.apply_user_defaults(tool)
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
        File
      "D:\all_applications\foruv\foruvcache\builds-v0\.tmpywcL19\Lib\site-packages\pyqtbuild\builder.py",
      line 49, in apply_user_defaults
          raise PyProjectOptionException('qmake',
                  "specify a working qmake or add it to PATH")
      sipbuild.pyproject.PyProjectOptionException

      hint: This usually indicates a problem with the package or the build
      environment.
  help: `pyqt5` (v5.15.2) was included because `paid-column1` (v0.1.0) depends      
        on `pyqt5`

2. 原因

原因出在pyqt5官方,他家就限制了最新版pyqt5依赖的pyqt5-qt5包不能在Windows平台上装。

3. 解决方案

我最终成功的解决方案是先uv syncuv pip install pyqt5。注意如果反过来会把环境改回pyproject.toml的环境,但我觉得uv速度这么快你每次都来一遍也没有关系:

Using Python 3.13.7 environment at: D:\Codes\uv_environment\example\.venv
Resolved 3 packages in 12.74s
Prepared 2 packages in 49.63s
Installed 3 packages in 296ms
 + pyqt5==5.15.11                                                                   
 + pyqt5-qt5==5.15.2
 + pyqt5-sip==12.17.2

其他提到的可能有用的解决方案:

  1. uv add pyqt5==5.15.11 pyqt5-qt5==5.15.21
  2. 在pyproject.toml中增加(跟上面一条其实是一样的,只是写法不同)2
    [dependency-groups]
    dev = [
        "pyqt5==5.15.11",
        "pyqt5-qt5==5.15.2",
    ]
    
    3
    deps = [
        "pyqt5>=5.15.11; sys_platform != 'win32'",
        "pyqt5<=5.15.2; sys_platform == 'win32'"
    ]
    
  3. 在pyproject.toml中增加3
    [tool.uv]
    constraint-dependencies = ["pyqt5-qt5 <=5.15.2"]
    
  4. 用PyQt6(草)4

  1. Bug Report: uv sync Fails to Install PyQt5 on Windows · Issue #11865 · astral-sh/uv ↩︎

  2. uv sync fails on PyQt5 but pip install is OK · Issue #15421 · astral-sh/uv ↩︎

  3. uv add pyqt5 error · Issue #7005 · astral-sh/uv ↩︎ ↩︎

  4. Add pyqt5-qt5 pin for uv add compatibility on Windows by TimMonko · Pull Request #7744 · napari/napari ↩︎

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

诸神缄默不语

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值