Installation and configuration of pyside2 in Python

Time:2021-9-12

In the past, when learning Java, I was exposed to writing GUI programs with swing. In my first job, the company’s induction training also taught me to write GUI clients with WPF. Today, I learned a new way: writing GUI programs using relevant libraries in Python.

In Python, there are many libraries that support graphical interface development. Today, we will mainly introduce the library pyside2. In this case, it should be compared and understood in combination with pyqt. The different protocols also determine their different use scenarios.

Pyqt is a GPLv3 protocol. If you use it in your program, your program will be open source. If you close the source, the business will violate the protocol (bear the consequences, and it doesn’t matter if you have a thick skin).

Pyside is an LGPL protocol. If you only use it as a library, your program can still be used for commercial purposes.

Install plug-ins:


pip install -U PySide2 -i  http://mirrors.aliyun.com/pypi/simple

After installation, enter% Python in the plug-in directory under the python installation directory_ In the home% \ lib \ site packages \ pyside2 directory, there will be a designer.exe file. Double click to open it. You can use the graphical page design tool to drag and drop the page:

The page after the tool opens is as follows:

The drag and drop page of the tool is similar to the plug-ins of graphical programming in other languages. On the left are some control options. What you need can be directly dragged to the panel on the right.

Is it inconvenient to open the plug-in installation directory every time? Here, you can use the function of pycharm’s extension to add the tool to the extension. The specific steps are as follows:

Open the setting page of pycharm and configure it according to the following figure:

After configuration, right-click a project directory of pycharm and select external tools to start the plug-in:

The design file of graphical page is a file ending in. UI, which can be converted into Python script through the tool of pyuic.exe in pyqt5.

Installation command:


pip install -U pyqt5 -i  http://mirrors.aliyun.com/pypi/simple

After installation, there is a pyside2-uic.exe file in the srripts directory of the python installation directory. You can use the following name to convert the. UI file into a python script:

CD / D UI file directory
pyside2-uic xxx.ui  -o  xxx.py

Of course, you can also add pyuic5 tool to pycharm’s extension tool. The specific configuration is as follows:

The text information of the configuration is attached for everyone to copy:


D:\Software\Python\Python39\Scripts\pyside2-uic.exe
$FileName$ -o $FileNameWithoutExtension$.py 
$FileDir$

The plug-in of pyside2 UIC in pychar uses:

Select the file of xxx.ui, right-click, and then select pyside2 UIC configured under external tools to generate a python script with the same file name and different suffixes in the same level directory. The script content is shown in the following figure:

(at this time, the python script cannot open the GUI page if it is run directly. You need to add some more code to start it. Please look forward to the following articles on how to run it.)

This is the end of this article about the installation and configuration of pyside2 in Python. For more information about the installation of pyside2 in Python, please search the previous articles of developeppaer or continue to browse the relevant articles below. I hope you will support developeppaer in the future!