Windows11 python3.12 安装pyqt6 pyqt6-tools

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

(venv) PS D:\python_project\pyqt6>  pip install pyqt6-tools
Collecting pyqt6-tools
  Using cached pyqt6_tools-6.4.2.3.3-py3-none-any.whl (29 kB)
Collecting click (from pyqt6-tools)
  Using cached click-8.1.7-py3-none-any.whl.metadata (3.0 kB)
Collecting pyqt6==6.4.2 (from pyqt6-tools)
  Using cached PyQt6-6.4.2-cp37-abi3-win_amd64.whl (6.4 MB)
INFO: pip is looking at multiple versions of pyqt6-tools to determine which version is compatible with other requirements. This could take a while.
Collecting pyqt6-tools
  Using cached pyqt6_tools-6.3.1.3.3-py3-none-any.whl (29 kB)
Collecting pyqt6==6.3.1 (from pyqt6-tools)
  Using cached PyQt6-6.3.1-cp37-abi3-win_amd64.whl (6.3 MB)
Collecting pyqt6-tools
  Using cached pyqt6_tools-6.1.0.3.2-py3-none-any.whl (29 kB)
Collecting pyqt6==6.1.0 (from pyqt6-tools)
  Using cached PyQt6-6.1.0.tar.gz (946 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... error
  error: subprocess-exited-with-error

  × Preparing metadata (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [25 lines of output]
      Traceback (most recent call last):
        File "D:\python_project\pyqt6\venv\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 353, in 
          main()
        File "D:\python_project\pyqt6\venv\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        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
          whl_basename = backend.build_wheel(metadata_directory, config_settings)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "C:\Users\Administrator\AppData\Local\Temp\pip-build-env-_zameq9a\overlay\Lib\site-packages\sipbuild\api.py", line 46, in build_wheel
          project = AbstractProject.bootstrap('wheel',
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "C:\Users\Administrator\AppData\Local\Temp\pip-build-env-_zameq9a\overlay\Lib\site-packages\sipbuild\abstract_project.py", line 87, in bootstrap
          project.setup(pyproject, tool, tool_description)
        File "C:\Users\Administrator\AppData\Local\Temp\pip-build-env-_zameq9a\overlay\Lib\site-packages\sipbuild\project.py", line 586, in setup
          self.apply_user_defaults(tool)
        File "C:\Users\Administrator\AppData\Local\Temp\pip-install-ehu53r9y\pyqt6_4b804778e8fb47789f82404b20ec89f5\project.py", line 60, in apply_user_defaults
          super().apply_user_defaults(tool)
        File "C:\Users\Administrator\AppData\Local\Temp\pip-build-env-_zameq9a\overlay\Lib\site-packages\pyqtbuild\project.py", line 70, in apply_user_defaults
          super().apply_user_defaults(tool)
        File "C:\Users\Administrator\AppData\Local\Temp\pip-build-env-_zameq9a\overlay\Lib\site-packages\sipbuild\project.py", line 237, in apply_user_defaults
          self.builder.apply_user_defaults(tool)
        File "C:\Users\Administrator\AppData\Local\Temp\pip-build-env-_zameq9a\overlay\Lib\site-packages\pyqtbuild\builder.py", line 69, in apply_user_defaults
          raise PyProjectOptionException('qmake',
      sipbuild.pyproject.PyProjectOptionException
      [end of output]

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

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

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

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

pyqt6的插件下载地址如下:

pyqt6-plugins · PyPI

Windows11 python3.12 安装pyqt6 pyqt6-tools_第1张图片

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

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

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

Windows11 python3.12 安装pyqt6 pyqt6-tools_第2张图片

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

Windows11 python3.12 安装pyqt6 pyqt6-tools_第3张图片

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

(venv) PS D:\python_project\pyqt6> pip install .\pyqt6_plugins-6.4.2.2.3-cp311-cp311-win_amd64.whl
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 进行安装。

(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/
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple/
Processing d:\python_project\pyqt6\pyqt6_plugins-6.4.2.2.3-py3-none-any.whl
Collecting click (from pyqt6-plugins==6.4.2.2.3)
  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/00/2e/d53fa4befbf2cfa713304affc7ca780ce4fc1fd8710527771b58311a3229/click-8.1.7-py3-none-any.whl (97 kB)
Requirement already satisfied: pyqt6 in d:\python_project\pyqt6\venv\lib\site-packages (from pyqt6-plugins==6.4.2.2.3) (6.6.0)
Collecting pyqt6-qt6==6.4.3 (from pyqt6-plugins==6.4.2.2.3)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/11/cf/9102346c5ea4cc2796d1eb2214593e5b65a500b2abaad258cadfe8cb3dca/PyQt6_Qt6-6.4.3-py3-none-win_amd64.whl (57.5 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 57.5/57.5 MB 32.8 MB/s eta 0:00:00
Collecting qt6-tools<6.4.3.2,>=6.4.3.1.2 (from pyqt6-plugins==6.4.2.2.3)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/18/5f/58fd48246779de82bd15a9cb1bface620fb7b6009ee5a5544f1a5ca39cdb/qt6_tools-6.4.3.1.3-py3-none-any.whl (13 kB)
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)
  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)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 71.3/71.3 MB 7.4 MB/s eta 0:00:00
Collecting colorama (from click->pyqt6-plugins==6.4.2.2.3)
  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/d1/d6/3965ed04c63042e047cb6a3e6ed1a63a35087b6a609aa3a15ed8ac56c221/colorama-0.4.6-py2.py3-none-any.whl (25 kB)
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)
INFO: pip is looking at multiple versions of pyqt6 to determine which version is compatible with other requirements. This could take a while.
Collecting pyqt6 (from pyqt6-plugins==6.4.2.2.3)
  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/d4/57/b4ce3b066da571d969e3b70135902d6a3903dc2f44a664867abbdd2bd734/PyQt6-6.5.3-cp37-abi3-win_amd64.whl (6.5 MB)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/0e/83/b5f0d005bb7d5bae034edadcb62dc70f9a1c242ed49eb333850136dc0b5c/PyQt6-6.5.2-cp37-abi3-win_amd64.whl (6.5 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 6.5/6.5 MB 8.0 MB/s eta 0:00:00
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/8e/a6/fdbfb2fbe303a3576220bdaafa77a8be64944fabbc0007bf50a2778fe4c7/PyQt6-6.5.1-cp37-abi3-win_amd64.whl (6.5 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 6.5/6.5 MB 14.3 MB/s eta 0:00:00
  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)
  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/7a/4e/4acc0ebe1f3231217bee58ec0f90ef6bdfbd6e0b7d08420c5ddb97780288/PyQt6-6.4.2-cp37-abi3-win_amd64.whl (6.4 MB)
Installing collected packages: pyqt6-qt6, qt6-applications, pyqt6, colorama, click, qt6-tools, pyqt6-plugins
  Attempting uninstall: pyqt6-qt6
    Found existing installation: PyQt6-Qt6 6.6.0
    Uninstalling PyQt6-Qt6-6.6.0:
      Successfully uninstalled PyQt6-Qt6-6.6.0
  Attempting uninstall: pyqt6
    Found existing installation: PyQt6 6.6.0
    Uninstalling PyQt6-6.6.0:
      Successfully uninstalled PyQt6-6.6.0
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文件夹里。

Windows11 python3.12 安装pyqt6 pyqt6-tools_第4张图片

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

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

pyuic6 -x main.ui -o win.py      

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

Windows11 python3.12 安装pyqt6 pyqt6-tools_第5张图片

直接运行:

还可以加载ui来运行。

使用教程里的代码:

from PyQt6.QtWidgets import QApplication, QWidget
import sys
from PyQt6 import uic


class UI(QWidget):
    def __int__(self):
        super().__init__()

        uic.loadUi("main.ui", self)


app = QApplication(sys.argv)
window = UI()
window.show()
app.exec()

出错:

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

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

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

from PyQt6 import uic
from PyQt6.QtWidgets import QApplication

Form, Window = uic.loadUiType("main.ui")
app = QApplication([])
window = Window()
form = Form()
form.setupUi(window)  # 配置外观
window.show()
app.exec()  # 转交控制权给pyQt6

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

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

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

Windows11 python3.12 安装pyqt6 pyqt6-tools_第6张图片

你可能感兴趣的:(pyqt6,python,pyqt6,pyqt6-tools)