使用Pyinstaller 打包PyQt5程序

打包操作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>

好了之后D:\Python\GPRS_Test_Server\dist\gprs_test_server_ui目录下有个对应的Exe文件

但是exe打不开。

直接放入命令行打开看下发现

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

就是说没有找到PyQt5

那我就尝试找到工程中的

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

下面有PyQt5的文件夹,直接放入到dist目录下

然后将exe拖至命令行中执行成功(但是执行的时候同时会弹出来cmd 窗口)

但是这样肯定不可行,你这个exe要放在其他电脑上就无法运行

所以还要想办法。。。。(还没有想到其他好办法)哪位大神有好的办法在下面留言说下,感激!

补充下-i 添加icon

-w 去掉命令行

还有如果icon没有改变,需要移动下exe的位置icon图标才会看到变化

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.

猜你喜欢

转载自blog.csdn.net/yangkunhenry/article/details/100779177