In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article focuses on "how to package pyqt5 into exe executable files". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to package pyqt5 into exe executable files.
Install python3.6
There are many problems with switching to exe, some of which are caused by the inappropriate version of python. If you can, try to use version 3.5or 3.6as much as possible.
Install python3.6.8 on Windows
Check the Add to path option to add to the environment variable during installation
Open the terminal to view the version:
Python-Vpip-V preparation work
Install the package:
Pip isntall pyinstallerpip install auto-py-to-exepip install pyqt5
If there are other dependent packages in the code, they should be installed accordingly. If the compilation is successful and the program dies directly after opening it, it is likely that the dependent packages are not installed.
Create a python file center.py
# center.pyimport sysfrom PyQt5.QtWidgets import QWidget, QDesktopWidget, QApplication class Example (QWidget): def _ _ init__ (self): super (). _ init__ () self.initUI () def initUI (self): self.resize Self.center () self.setWindowTitle ('Center') self.show () # method for controlling window display in the center of the screen def center (self): # get the window qr = self.frameGeometry () # get the screen center point cp = QDesktopWidget (). AvailableGeometry (). Center () # display Show to the center of the screen qr.moveCenter (cp) self.move (qr.topLeft ()) if _ _ name__ ='_ _ main__': app = QApplication (sys.argv) ex = Example () sys.exit (app.exec_ ())
When you run python center.py, you can see a window in the center of the screen, indicating that the code is fine, which is necessary, and if the code doesn't work, the compilation won't work.
Compile
Pyinstaller is not a cross-compiler, and exe can only be compiled on Windows to run on Windows.
Pyinstaller compiles python code into an exe executable file for use on Windows
Python:3.6-3.9
Pip install pyinstaller
Auto-py-to-exe uses pyinstaller through a visual interface
Python: 3.5-3.9
Pip install auto-py-to-exe
Auto-py-to-exe
Start auto-py-to-exe
Auto-py-to-exe single file
After startup, select the corresponding file, try the single file first, and select window-based
The corresponding command is:
Pyinstaller-noconfirm-onefile-windowed-icon "D:/01ubuntu/Icon.ico"D:/01ubuntu/center.py"
Because startup is not based on the console, you need to rely on bootloader, and if you cannot find bootloader, you will get an error:
Choose to be based on the console, that is, when you start, the terminal black window will pop up.
Corresponding to the generated command:
Pyinstaller-noconfirm-onefile-console-icon "D:/01ubuntu/Icon.ico"D:/01ubuntu/center.py"
After running successfully, the generated exe file is under the ouput file:
Double-click center.exe and you'll see a black box pop up, and then the pyqt interface will come out, but it's a little slow.
Compiled successfully, but the black window is a little ugly.
Single directory
Corresponding command:
Pyinstaller-noconfirm-onedir-console-icon "D:/01ubuntu/Icon.ico"D:/01ubuntu/center.py"
The result is no longer a single exe file, but a folder containing the seed files needed to start center.py
It still contains the center.exe executable file, but you can find that the exe is much smaller now, because the rest of the file is visible, double-click can still open it, and this time the startup speed is much faster.
Complete project
Corresponding command:
Pyinstaller-- noconfirm-- onedir-- console-- icon "D:/01ubuntu/myApp/Icon.ico"-- add-data "DVV Unix 01ubuntuGet MyApp Maple Win.pyTe."-- add-data "DVV" DVV Unix 01ubuntuThese images / "" D:/01ubuntu/myApp/main.py "solution can't find bootloader
At the time of compilation, the antivirus software happily reported to me that he had caught the thief. As a result, the hole in front of him was dug by the antivirus software that asked for credit.
Click to find the original file to enter his house and find that everything I want is locked in a small room by antivirus software.
After the check box, click to restore the selected rescue, but fortunately these documents have not been tortured.
Send them back to where they were supposed to be.
TODO
Convert the compilation result to an installable file
At this point, I believe you have a deeper understanding of "how to package pyqt5 into exe executable files". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.