PyCharm+PyQt5 : 主讲解决安装PyQt5 打开designer等时报错问题

主讲解决安装PyQt5 打开designer等时报错问题, 其他的参考都说的很明白了

.1. PyQt5安装

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

   Qt for Python支持

 2. PyQt5-tools

    主要就是designer等工具

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


3 出现问题

32位Python的xxxx\Python38-32\Lib\site-packages\pyqt5_tools\Qt\bin的目录

64位Python的xxxx\Python38-32\Lib\site-packages\pyqt5_tools\Qt\bin的目录

扫描二维码关注公众号,回复: 11323650 查看本文章

出问题是在64bit

  

解决方法: 将xxx\Python38\Lib\site-packages\pyqt5_tools\Qt 目录下的 plugins 合并进 xxx\Python38\Lib\site-packages\pyqt5_tools\Qt\bin目录下即可

Note: 安装之后的 designer等Qt工具都在 xxx\Python38\Lib\site-packages\pyqt5_tools\Qt\bin 目录下

4. Pycharm设置外部工具

   目的主要是在IDE操作时方便, 参考自   https://blog.csdn.net/zhengbin9/article/details/82729914

   在PyCharm里打开Settings → Tools → External Tools添加如下:

   Name:QtDesigner
   Program:C:\Python36\Lib\site-packages\pyqt5-tools\designer.exe
   Working directory:$FileDir$

  Name:PyUIC
  Program:C:\Python36\python3.exe
  Arguments:-m PyQt5.uic.pyuic $FileName$ -o $FileNameWithoutExtension$.py
  Working directory:$FileDir$

  Name:PyInstaller
  Program:C:\Python36\Scripts\pyinstaller.exe
  Arguments:--paths C:\Python36\Lib\site-packages\PyQt5\Qt\bin -F -w $FileNameWithoutExtension$.py
  Working directory:$FileDir$

5 实例

login.ui -> login.py

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'login.ui'
#
# Created by: PyQt5 UI code generator 5.14.2
#
# WARNING! All changes made in this file will be lost!


from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_Form(object):
    def setupUi(self, Form):
        Form.setObjectName("Form")
        Form.resize(400, 115)
        self.gridLayout = QtWidgets.QGridLayout(Form)
        self.gridLayout.setObjectName("gridLayout")
        self.checkBox = QtWidgets.QCheckBox(Form)
        self.checkBox.setObjectName("checkBox")
        self.gridLayout.addWidget(self.checkBox, 3, 0, 1, 3)
        self.widget = QtWidgets.QWidget(Form)
        self.widget.setObjectName("widget")
        self.horizontalLayout = QtWidgets.QHBoxLayout(self.widget)
        self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
        self.horizontalLayout.setSpacing(0)
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.pushButton = QtWidgets.QPushButton(self.widget)
        self.pushButton.setObjectName("pushButton")
        self.horizontalLayout.addWidget(self.pushButton)
        self.pushButton_2 = QtWidgets.QPushButton(self.widget)
        self.pushButton_2.setObjectName("pushButton_2")
        self.horizontalLayout.addWidget(self.pushButton_2)
        self.gridLayout.addWidget(self.widget, 4, 0, 1, 3)
        self.label = QtWidgets.QLabel(Form)
        self.label.setObjectName("label")
        self.gridLayout.addWidget(self.label, 0, 0, 1, 2)
        self.label_2 = QtWidgets.QLabel(Form)
        self.label_2.setObjectName("label_2")
        self.gridLayout.addWidget(self.label_2, 2, 0, 1, 2)
        self.lineEdit_2 = QtWidgets.QLineEdit(Form)
        self.lineEdit_2.setObjectName("lineEdit_2")
        self.gridLayout.addWidget(self.lineEdit_2, 2, 2, 1, 1)
        self.lineEdit = QtWidgets.QLineEdit(Form)
        self.lineEdit.setObjectName("lineEdit")
        self.gridLayout.addWidget(self.lineEdit, 0, 2, 1, 1)

        self.retranslateUi(Form)
        QtCore.QMetaObject.connectSlotsByName(Form)

    def retranslateUi(self, Form):
        _translate = QtCore.QCoreApplication.translate
        Form.setWindowTitle(_translate("Form", "Form"))
        self.checkBox.setText(_translate("Form", "记住密码"))
        self.pushButton.setText(_translate("Form", "取消"))
        self.pushButton_2.setText(_translate("Form", "确定"))
        self.label.setText(_translate("Form", "用户名"))
        self.label_2.setText(_translate("Form", "密码"))

main.py 调用

import sys
from PyQt5 import QtWidgets
from login import Ui_Form

if __name__=="__main__":
    app = QtWidgets.QApplication(sys.argv)
    widget = QtWidgets.QWidget()
    ui = Ui_Form()
    ui.setupUi(widget)
    widget.show()
    sys.exit(app.exec_())

结果

参考:

windows 环境安装PyQt5 - https://www.cnblogs.com/liuhedong/p/11545568.html

Qt for Python PyCharm... - https://blog.csdn.net/halo_hsuh/article/details/106124339

浅尝Qt for Python - https://blog.csdn.net/halo_hsuh/article/details/106030201

PyQt5教程 - http://code.py40.com/

猜你喜欢

转载自blog.csdn.net/halo_hsuh/article/details/106128954
今日推荐