First, use Anaconda to create a virtual environment (named qt here) to isolate it from other projects.
Python version 3.7.11
1. Install PyQt5
Applicable to windows,
first execute the following two instructions to install the relevant libraries of pyqt5
# 第一条
pip install PyQt5 -i https://pypi.douban.com/simple
# 第二条
pip install PyQt5-tools -i https://pypi.douban.com/simple
PyQt5 no longer provides commonly used Qt tools, such as the graphical interface development tool Qt Designer and the international translation tool Liguist. If these are used in development, you must install the Qt tools yourself PyQt5-tools
.
2. Configure External Tools in PyCharm
1、Qt Designer
Qt Designer is the implementation tool for the UI interface of the PyQt program. Using Qt Designer, you can drag and click to complete the GUI interface design.
First find it in the virtual environment directory of anaconda QT Designer.exe
. My path here is:
G:\software\Anaconda3\envs\qt\Lib\site-packages\qt5_applications\Qt\bin
open pycharm——>File——>settings——>Tools——>External Tools——> +
fill in as shown in the figure below, Program
the path is as above Write the path, Working directory
fill in: $FileDir$
, click OK
2、PyUIC
PyUIC can convert .ui files generated by Qt Designer into py files.
First find pyuic5.exe
, my path here is:
G:\software\Anaconda3\envs\qt\Scripts\pyuic5.exe
Then fill it in according to the picture below, where the Arguments
writing $FileName$ -o $FileNameWithoutExtension$.py
tool is configured.
3. Test
This step tests whether the environment is configured successfully.
Right-click the project folder——>External Tools——> Qt Designer
to open the Qt Designer interface, draw an interface, and save it as a .ui file. Right-click the .ui file
in pycharm ——>External Tools——> PyUIC
in the same A py file with the same name will be generated in the directory
Then create a new py file, write the following code, and run:
import sys
import test
from PyQt5.QtWidgets import QWidget, QApplication, QMainWindow
app = QApplication(sys.argv)
MainWindow = QMainWindow()
ui = test.Ui_Dialog()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec())
It now runs successfully and the environment installation is complete.