安装第三方库出错方法
- 错误:Cannot unpack file xxxx
进入到Project Interpreter目录,然后使用命令安装:
PyQt5安装
基于之前已经安装且配置了python环境3.6
Configuration—>Setting–>Project Interpreter->选择解析器(根据自己安装的目录而定)
点击绿色的“+”,弹出Avaiable Package对话框,在该对话框的“Manage Repositories”里面填写国内的镜像,主要有豆瓣,阿里,中科大,清华等,如下所示
安装PyQt5需要的package
安装所需要的python库:
- SIP
- PyQt5
- PyQt5Designer
- PyQt5-tools
届时,在Lib/site-packages下会生成安装目录
添加环境变量
将其安装路径添加到系统环境变量中
在pycharm中配置PyQt5工具
配置QtDesigner
- 输入工具的名字:QT Desiner
- Program:选择之前安装的.exe文件(C:\Users\wu-287\venv\Lib\site-packages\pyqt5_tools\Qt\bin\designer.exe)
- 选择FileExt – File extension,working directory:$FileDir$
配置UIC工具
1. 配置名称PyQT_UIC //可自定义名字
2. 找到相应的目录程序 //pyuic的安装路径
3. Argument:$FileName$ -o $FileNameWithoutExtension$.py
4. $FileDir$
完成后可以在pycharm中打开QtDesigner
Tool->Qt Designer.点击后弹出如下Qt Designer 对话框
Hello.ui
使用Qt Designer生成一个最简单的Hello界面,右键点击External Tools—>PyQTUIC
import sys # self add
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QApplication, QMainWindow #self add
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(800, 600)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(330, 240, 161, 51))
self.label.setObjectName("label")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 23))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.label.setText(_translate("MainWindow", "Hello PyQt5"))
"""
self add for run
"""
if __name__ == '__main__':
app = QApplication(sys.argv)
MainWindow = QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())