Recently, I am going to learn Python GUI. In addition to writing code, I think the quickest way is PyQt. In the process of configturing the environment, the online tutorials are based on Windows, and some are based on Ubuntu. We finally got it. How to install in Ubuntu:

sudo apt-get install qttools5-dev-tools

but:…… Error under CentOS…

Python installation

There’s not much to say about this part. There are plenty of tutorials online, just follow the guide.

Install PyQT5

There are two ways to install PyQT5, one is to download the source code from the official website, the other is to use PIP to install.

I recommend using a PIP installation here. Because it will automatically select the appropriate version of PyQT5 based on your Python version, if you manually download the source code installation, you will inevitably choose the wrong version. It is recommended to use a more secure installation method.

pip3 install PyQt5

General this way in the domestic environment will be relatively slow, may prompt installation failure, here is recommended to use the domestic installation source (Douban) way to solve:

pip install PyQt5 -i
https://pypi.douban.com/simple

Install PyQT5-Tools

Also use domestic mirror installation

pip install PyQt5-tools -i
https://pypi.douban.com/simple

IV. Configure VS Code

1. Install the PyQt Integration extension

Because we did not install Qt Designer separately, we have already installed Qt Designer when we installed PyQT5-Tools, and the path of each computer is different. So it’s a bit of a hassle to find at first, and it’s recommended to use the Linux find command to locate the relevant files.

find / -name designer


Once you find the Qt Designer path, copy and configure it in PyQt Integration

In File Management, right-click on the empty space and select PyQt :New Form to create a Form

Open Qt Designer and create a form to save the UI file and return to VS Code

Right-click on the UI file you just created and select Pyqt: Compile Form to generate a Python file with the same name

Generated code:

Trying to run the newly generated “ui_mainus.py” is useless because the generated file does not have a program entry. So let’s create a separate program called “main.py” in the same directory and type the following to replace UI_Untitled with the.py file name you generated.

import sys
from PyQt5.QtWidgets import QApplication, QMainWindow

import Ui_mainus

if __name__ == '__main__':
    app = QApplication(sys.argv)
    MainWindow = QMainWindow()
    ui = Ui_mainus.Ui_Dialog()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())

So far, we have completed the task of installing PyQT5, Qt Designer and configuring VS Code in CentOS 7. I am also in the process of learning PyQT5, welcome your comments.