• Windows11 python3.12 安装pyqt6 pyqt6-tools


    Windows11 python3.12 安装pyqt6比较容易,但pyqt6-tools一直安装不上去。出错信息如下:

    1. (venv) PS D:\python_project\pyqt6> pip install pyqt6-tools
    2. Collecting pyqt6-tools
    3. Using cached pyqt6_tools-6.4.2.3.3-py3-none-any.whl (29 kB)
    4. Collecting click (from pyqt6-tools)
    5. Using cached click-8.1.7-py3-none-any.whl.metadata (3.0 kB)
    6. Collecting pyqt6==6.4.2 (from pyqt6-tools)
    7. Using cached PyQt6-6.4.2-cp37-abi3-win_amd64.whl (6.4 MB)
    8. INFO: pip is looking at multiple versions of pyqt6-tools to determine which version is compatible with other requirements. This could take a while.
    9. Collecting pyqt6-tools
    10. Using cached pyqt6_tools-6.3.1.3.3-py3-none-any.whl (29 kB)
    11. Collecting pyqt6==6.3.1 (from pyqt6-tools)
    12. Using cached PyQt6-6.3.1-cp37-abi3-win_amd64.whl (6.3 MB)
    13. Collecting pyqt6-tools
    14. Using cached pyqt6_tools-6.1.0.3.2-py3-none-any.whl (29 kB)
    15. Collecting pyqt6==6.1.0 (from pyqt6-tools)
    16. Using cached PyQt6-6.1.0.tar.gz (946 kB)
    17. Installing build dependencies ... done
    18. Getting requirements to build wheel ... done
    19. Preparing metadata (pyproject.toml) ... error
    20. error: subprocess-exited-with-error
    21. × Preparing metadata (pyproject.toml) did not run successfully.
    22. │ exit code: 1
    23. ╰─> [25 lines of output]
    24. Traceback (most recent call last):
    25. File "D:\python_project\pyqt6\venv\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 353, in
    26. main()
    27. File "D:\python_project\pyqt6\venv\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 335, in main
    28. json_out['return_val'] = hook(**hook_input['kwargs'])
    29. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    30. File "D:\python_project\pyqt6\venv\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 152, in prepare_metadata_for_build_wheel
    31. whl_basename = backend.build_wheel(metadata_directory, config_settings)
    32. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    33. File "C:\Users\Administrator\AppData\Local\Temp\pip-build-env-_zameq9a\overlay\Lib\site-packages\sipbuild\api.py", line 46, in build_wheel
    34. project = AbstractProject.bootstrap('wheel',
    35. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    36. File "C:\Users\Administrator\AppData\Local\Temp\pip-build-env-_zameq9a\overlay\Lib\site-packages\sipbuild\abstract_project.py", line 87, in bootstrap
    37. project.setup(pyproject, tool, tool_description)
    38. File "C:\Users\Administrator\AppData\Local\Temp\pip-build-env-_zameq9a\overlay\Lib\site-packages\sipbuild\project.py", line 586, in setup
    39. self.apply_user_defaults(tool)
    40. File "C:\Users\Administrator\AppData\Local\Temp\pip-install-ehu53r9y\pyqt6_4b804778e8fb47789f82404b20ec89f5\project.py", line 60, in apply_user_defaults
    41. super().apply_user_defaults(tool)
    42. File "C:\Users\Administrator\AppData\Local\Temp\pip-build-env-_zameq9a\overlay\Lib\site-packages\pyqtbuild\project.py", line 70, in apply_user_defaults
    43. super().apply_user_defaults(tool)
    44. File "C:\Users\Administrator\AppData\Local\Temp\pip-build-env-_zameq9a\overlay\Lib\site-packages\sipbuild\project.py", line 237, in apply_user_defaults
    45. self.builder.apply_user_defaults(tool)
    46. File "C:\Users\Administrator\AppData\Local\Temp\pip-build-env-_zameq9a\overlay\Lib\site-packages\pyqtbuild\builder.py", line 69, in apply_user_defaults
    47. raise PyProjectOptionException('qmake',
    48. sipbuild.pyproject.PyProjectOptionException
    49. [end of output]
    50. note: This error originates from a subprocess, and is likely not a problem with pip.
    51. error: metadata-generation-failed
    52. × Encountered error while generating package metadata.
    53. ╰─> See above for output.
    54. note: This is an issue with the package mentioned above, not pip.
    55. hint: See above for details.

    找了一圈,终于找到了解决办法,用python3.11的插件包进行安装,有了环境,就可以正常安装pyqt6-tools了。

    如果不想做下面的自己动手步骤,可以看文章顶部的下载资源,直接下载后安装即可。

    pyqt6的插件下载地址如下:

    pyqt6-plugins · PyPI

    看上图,目前只有cp311,就是python3.11的版本,还没有python3.12的版本。那就用这个插件包,可行的原因可能是差别不大?

    下载后的文件名是:pyqt6_plugins-6.4.2.2.3-cp311-cp311-win_amd64.whl

    打开winrar,把这个拖进去,找到info文件夹,里面有个METADATA文件,拖出来,用记事本修改里面的信息。

    把Requires-Dist: pyqt6 后面的限定版本删去,修改为下面这样。

     保存,然后替换压缩包里的同名文件。在终端里,使用pip install 安装这个whl文件,安装前,必须要改名,因为文件名里有cp311,跟系统python3.12版本不一样,会出现错误:

    1. (venv) PS D:\python_project\pyqt6> pip install .\pyqt6_plugins-6.4.2.2.3-cp311-cp311-win_amd64.whl
    2. ERROR: pyqt6_plugins-6.4.2.2.3-cp311-cp311-win_amd64.whl is not a supported wheel on this platform.

    修改文件名为:pyqt6_plugins-6.4.2.2.3-py3-none-any.whl,再pip install 进行安装。

    1. (venv) PS D:\python_project\pyqt6> pip install .\pyqt6_plugins-6.4.2.2.3-py3-none-any.whl -i https://pypi.tuna.tsinghua.edu.cn/simple/
    2. Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple/
    3. Processing d:\python_project\pyqt6\pyqt6_plugins-6.4.2.2.3-py3-none-any.whl
    4. Collecting click (from pyqt6-plugins==6.4.2.2.3)
    5. Using cached https://pypi.tuna.tsinghua.edu.cn/packages/00/2e/d53fa4befbf2cfa713304affc7ca780ce4fc1fd8710527771b58311a3229/click-8.1.7-py3-none-any.whl (97 kB)
    6. Requirement already satisfied: pyqt6 in d:\python_project\pyqt6\venv\lib\site-packages (from pyqt6-plugins==6.4.2.2.3) (6.6.0)
    7. Collecting pyqt6-qt6==6.4.3 (from pyqt6-plugins==6.4.2.2.3)
    8. Downloading https://pypi.tuna.tsinghua.edu.cn/packages/11/cf/9102346c5ea4cc2796d1eb2214593e5b65a500b2abaad258cadfe8cb3dca/PyQt6_Qt6-6.4.3-py3-none-win_amd64.whl (57.5 MB)
    9. ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 57.5/57.5 MB 32.8 MB/s eta 0:00:00
    10. Collecting qt6-tools<6.4.3.2,>=6.4.3.1.2 (from pyqt6-plugins==6.4.2.2.3)
    11. Downloading https://pypi.tuna.tsinghua.edu.cn/packages/18/5f/58fd48246779de82bd15a9cb1bface620fb7b6009ee5a5544f1a5ca39cdb/qt6_tools-6.4.3.1.3-py3-none-any.whl (13 kB)
    12. Collecting qt6-applications<6.4.3.3,>=6.4.3.2.2 (from qt6-tools<6.4.3.2,>=6.4.3.1.2->pyqt6-plugins==6.4.2.2.3)
    13. Downloading https://pypi.tuna.tsinghua.edu.cn/packages/c9/39/eb4d4c22b7785cd31713a8354ca97eb2ffe95f1a8809ea06e21d762d0bc7/qt6_applications-6.4.3.2.3-py3-none-win_amd64.whl (71.3 MB)
    14. ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 71.3/71.3 MB 7.4 MB/s eta 0:00:00
    15. Collecting colorama (from click->pyqt6-plugins==6.4.2.2.3)
    16. Using cached https://pypi.tuna.tsinghua.edu.cn/packages/d1/d6/3965ed04c63042e047cb6a3e6ed1a63a35087b6a609aa3a15ed8ac56c221/colorama-0.4.6-py2.py3-none-any.whl (25 kB)
    17. Requirement already satisfied: PyQt6-sip<14,>=13.6 in d:\python_project\pyqt6\venv\lib\site-packages (from pyqt6->pyqt6-plugins==6.4.2.2.3) (13.6.0)
    18. INFO: pip is looking at multiple versions of pyqt6 to determine which version is compatible with other requirements. This could take a while.
    19. Collecting pyqt6 (from pyqt6-plugins==6.4.2.2.3)
    20. Using cached https://pypi.tuna.tsinghua.edu.cn/packages/d4/57/b4ce3b066da571d969e3b70135902d6a3903dc2f44a664867abbdd2bd734/PyQt6-6.5.3-cp37-abi3-win_amd64.whl (6.5 MB)
    21. Downloading https://pypi.tuna.tsinghua.edu.cn/packages/0e/83/b5f0d005bb7d5bae034edadcb62dc70f9a1c242ed49eb333850136dc0b5c/PyQt6-6.5.2-cp37-abi3-win_amd64.whl (6.5 MB)
    22. ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 6.5/6.5 MB 8.0 MB/s eta 0:00:00
    23. Downloading https://pypi.tuna.tsinghua.edu.cn/packages/8e/a6/fdbfb2fbe303a3576220bdaafa77a8be64944fabbc0007bf50a2778fe4c7/PyQt6-6.5.1-cp37-abi3-win_amd64.whl (6.5 MB)
    24. ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 6.5/6.5 MB 14.3 MB/s eta 0:00:00
    25. Using cached https://pypi.tuna.tsinghua.edu.cn/packages/3b/b3/68fa3deb9d83f8e5ad880b09e85359a67d8b7975513fd2688ca295a86703/PyQt6-6.5.0-1-cp37-abi3-win_amd64.whl (6.5 MB)
    26. Using cached https://pypi.tuna.tsinghua.edu.cn/packages/7a/4e/4acc0ebe1f3231217bee58ec0f90ef6bdfbd6e0b7d08420c5ddb97780288/PyQt6-6.4.2-cp37-abi3-win_amd64.whl (6.4 MB)
    27. Installing collected packages: pyqt6-qt6, qt6-applications, pyqt6, colorama, click, qt6-tools, pyqt6-plugins
    28. Attempting uninstall: pyqt6-qt6
    29. Found existing installation: PyQt6-Qt6 6.6.0
    30. Uninstalling PyQt6-Qt6-6.6.0:
    31. Successfully uninstalled PyQt6-Qt6-6.6.0
    32. Attempting uninstall: pyqt6
    33. Found existing installation: PyQt6 6.6.0
    34. Uninstalling PyQt6-6.6.0:
    35. Successfully uninstalled PyQt6-6.6.0
    36. Successfully installed click-8.1.7 colorama-0.4.6 pyqt6-6.4.2 pyqt6-plugins-6.4.2.2.3 pyqt6-qt6-6.4.3 qt6-applications-6.4.3.2.3 qt6-tools-6.4.3.1.3

    尾部加上清华的镜像,速度飞快啊,建议安装任何包都可以加上这个后缀,就是pip install xxx 后面加上:

    -i https://pypi.tuna.tsinghua.edu.cn/simple/

    这个时候再安装pyqt6-tools一路顺畅。

     pip install pyqt6-tools  -i https://pypi.tuna.tsinghua.edu.cn/simple/
    

    我是在env里安装的,qt designer在 qt6_application文件夹里。

    可以发送快捷方式到桌面。打开设计一个窗体。存储到工程文件夹里,命名main.ui。

    使用命令把ui设计文件转换成python代码:

    pyuic6 -x main.ui -o win.py      

    直接运行这个win.py文件就可以了,里面都是自动转换成python的代码。

    直接运行:

    还可以加载ui来运行。

    使用教程里的代码:

    1. from PyQt6.QtWidgets import QApplication, QWidget
    2. import sys
    3. from PyQt6 import uic
    4. class UI(QWidget):
    5. def __int__(self):
    6. super().__init__()
    7. uic.loadUi("main.ui", self)
    8. app = QApplication(sys.argv)
    9. window = UI()
    10. window.show()
    11. app.exec()

    出错:

    1. D:\python_project\pyqt6\app.py:14: DeprecationWarning: sipPyTypeDict() is deprecated, the extension module should use sipPyTypeDictRef() instead
    2. window = UI()
    3. libpng warning: iCCP: cHRM chunk does not match sRGB

    使用很多教程里面的,都是出现上面这样的错误。

    终于找到一个可以正常运行的:

    1. from PyQt6 import uic
    2. from PyQt6.QtWidgets import QApplication
    3. Form, Window = uic.loadUiType("main.ui")
    4. app = QApplication([])
    5. window = Window()
    6. form = Form()
    7. form.setupUi(window) # 配置外观
    8. window.show()
    9. app.exec() # 转交控制权给pyQt6

    上面的代码里form.setupUi(window)  # 配置外观这一句,是不是有点自己加载自己的感觉啊?我这萌新已经一头浆糊了。

    感谢:pyqt6导入和加载Qt Designer的ui档案_九是否随机的称呼的博客-CSDN博客

    感谢:pip - Cannot install PyQt6 tools in Python 3.11 on Windows - Stack Overflow

  • 相关阅读:
    《古代汉语》上下册课后习题答案
    图片怎么转换成PDF格式?这两种方法赶紧记下
    HOOPS/MVO技术概述
    如何做好测试用例设计
    ETCD快速入门-01 ETCD概述
    HarmonyOS方舟开发框架容器类API的介绍与使用
    我为什么建议不要用CMake
    CO41创建生产订单维护增强字段
    【云原生】MySql索引分析及查询优化
    执行sql,提示Illegal instruction(非法指令)
  • 原文地址:https://blog.csdn.net/andux/article/details/134476146