Use Pyinstaller to package PyQt5 programs

Packaging operation pyinstaller --hidden-import=PyQt5 gprs_test_server_ui.py

D:\Python\GPRS_Test_Server>pyinstaller --hidden-import=PyQt5 gprs_test_server_ui.py
163 INFO: PyInstaller: 3.4
164 INFO: Python: 3.7.3
164 INFO: Platform: Windows-10-10.0.10240-SP0
178 INFO: wrote D:\Python\GPRS_Test_Server\gprs_test_server_ui.spec
182 INFO: UPX is not available.
184 INFO: Extending PYTHONPATH with paths
['D:\\Python\\GPRS_Test_Server', 'D:\\Python\\GPRS_Test_Server']
185 INFO: checking Analysis
228 INFO: checking PYZ
251 INFO: checking PKG
253 INFO: Bootloader C:\Users\nasri.yang\AppData\Roaming\Python\Python37\site-packages\PyInstaller\bootloader\Windows-64bit\run.exe
254 INFO: checking EXE
255 INFO: Rebuilding EXE-00.toc because gprs_test_server_ui.exe missing
256 INFO: Building EXE from EXE-00.toc
256 INFO: Appending archive to EXE D:\Python\GPRS_Test_Server\build\gprs_test_server_ui\gprs_test_server_ui.exe
393 INFO: Building EXE from EXE-00.toc completed successfully.
408 INFO: checking COLLECT
410 INFO: Building COLLECT COLLECT-00.toc
1877 INFO: Building COLLECT COLLECT-00.toc completed successfully.

D:\Python\GPRS_Test_Server>

After that, there is a corresponding Exe file in the D:\Python\GPRS_Test_Server\dist\gprs_test_server_ui directory

But the exe cannot be opened.

Put it directly into the command line to open it and find out

C:\Users\nasri.yang>D:\Python\GPRS_Test_Server\dist\gprs_test_server_ui.exe
Traceback (most recent call last):
  File "gprs_test_server_ui.py", line 9, in <module>
ModuleNotFoundError: No module named 'PyQt5'
[7248] Failed to execute script gprs_test_server_ui

It means that PyQt5 is not found

Then I will try to find the

D:\Python\GPRS_Test_Server\env\Lib\site-packages

There is a PyQt5 folder below, put it directly into the dist directory

Then drag the exe to the command line and execute it successfully (but a cmd window will pop up when it is executed)

 

But this is definitely not feasible, your exe cannot be run if you put it on another computer

So we have to find a way. . . . (I haven't thought of other good ways yet) Which great god has a good way, leave a comment below, thank you!

Supplement -i add icon

-w remove the command line

Also, if the icon does not change, you need to move the exe location to see the change.

D:\Python\GPRS_Test_Server>pyinstaller --hidden-import=PyQt5 gprs_test_server_ui.py -w -i GPRS_Test_Server.ico
93 INFO: PyInstaller: 3.4
93 INFO: Python: 3.7.3
94 INFO: Platform: Windows-10-10.0.10240-SP0
96 INFO: wrote D:\Python\GPRS_Test_Server\gprs_test_server_ui.spec
100 INFO: UPX is not available.
105 INFO: Extending PYTHONPATH with paths
['D:\\Python\\GPRS_Test_Server', 'D:\\Python\\GPRS_Test_Server']
106 INFO: checking Analysis
135 INFO: checking PYZ
150 INFO: checking PKG
151 INFO: Bootloader C:\Users\nasri.yang\AppData\Roaming\Python\Python37\site-packages\PyInstaller\bootloader\Windows-64bit\runw.exe
151 INFO: checking EXE
157 INFO: Building because icon changed
157 INFO: Building EXE from EXE-00.toc
161 INFO: SRCPATH [('GPRS_Test_Server.ico', None)]
162 INFO: Updating icons from ['GPRS_Test_Server.ico'] to C:\Users\NASRI~1.YAN\AppData\Local\Temp\tmpg5ljes27
221 INFO: Writing RT_GROUP_ICON 0 resource with 146 bytes
222 INFO: Writing RT_ICON 1 resource with 1640 bytes
222 INFO: Writing RT_ICON 2 resource with 744 bytes
222 INFO: Writing RT_ICON 3 resource with 296 bytes
223 INFO: Writing RT_ICON 4 resource with 3752 bytes
223 INFO: Writing RT_ICON 5 resource with 2216 bytes
223 INFO: Writing RT_ICON 6 resource with 1384 bytes
223 INFO: Writing RT_ICON 7 resource with 67624 bytes
223 INFO: Writing RT_ICON 8 resource with 9640 bytes
224 INFO: Writing RT_ICON 9 resource with 4264 bytes
224 INFO: Writing RT_ICON 10 resource with 1128 bytes
228 INFO: Appending archive to EXE D:\Python\GPRS_Test_Server\build\gprs_test_server_ui\gprs_test_server_ui.exe
287 INFO: Building EXE from EXE-00.toc completed successfully.
290 INFO: checking COLLECT
WARNING: The output directory "D:\Python\GPRS_Test_Server\dist\gprs_test_server_ui" and ALL ITS CONTENTS will be REMOVED! Continue? (y/n)y
2403 INFO: Removing dir D:\Python\GPRS_Test_Server\dist\gprs_test_server_ui
2424 INFO: Building COLLECT COLLECT-00.toc
2710 INFO: Building COLLECT COLLECT-00.toc completed successfully.

 

Guess you like

Origin blog.csdn.net/yangkunhenry/article/details/100779177