python打包如何加图标(Python教你如何打包带图标的程序)
使用pyinstaller打包的时候,默认会有一个程序图标,如果你想自定义的话可以使用下面的参数去改变你的软件图标,语法如下:
pyinstaller -F -i <图标文件.ico> <需要打包的程序.py>
例如我需要打包一个GUI程序,图标文件是当前目录下的
Y.ico
那么我需要执行的命令就是
pyinstaller -F -w -i .\Y.ico -p .\venv\Lib\site-packages\ .\Windows_GUI.py
其中:
-w #取消终端
-p #指定依赖包,如果你的程序使用了其他的模块,那么就需要指定,不然会出错
实践
PS D:\迅雷下载\dd\IP\Client> pyinstaller -F -w -i .\Y.ico -p .\venv\Lib\site-packages\ .\Windows_GUI.py
85 INFO: PyInstaller: 4.2
85 INFO: Python: 3.9.1
88 INFO: Platform: Windows-10-10.0.18362-SP0
93 INFO: wrote D:\迅雷下载\dd\IP\Client\Windows_GUI.spec
97 INFO: UPX is not available.
99 INFO: Extending PYTHONPATH with paths
['D:\\迅雷下载\\dd\\IP\\Client',
'D:\\迅雷下载\\dd\\IP\\Client\\venv\\Lib\\site-packages',
'D:\\迅雷下载\\dd\\IP\\Client']
109 INFO: checking Analysis
224 INFO: checking PYZ
258 INFO: checking PKG
324 INFO: Building because D:\迅雷下载\dd\IP\Client\build\Windows_GUI\Windows_GUI.exe.manifest changed
324 INFO: Building PKG (CArchive) PKG-00.pkg
3516 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
13800 INFO: Bootloader c:\program files\python39\lib\site-packages\PyInstaller\bootloader\Windows-64bit\runw.exe
13800 INFO: checking EXE
13814 INFO: Building because console changed
13815 INFO: Building EXE from EXE-00.toc
13822 INFO: Copying icons from ['Y.ico']
13824 INFO: Writing RT_GROUP_ICON 0 resource with 20 bytes
13825 INFO: Writing RT_ICON 1 resource with 270376 bytes
13837 INFO: Updating manifest in D:\迅雷下载\dd\IP\Client\build\Windows_GUI\runw.exe.1owx3kiv
13838 INFO: Updating resource type 24 name 1 language 0
13847 INFO: Appending archive to EXE D:\迅雷下载\dd\IP\Client\dist\Windows_GUI.exe
13868 INFO: Building EXE from EXE-00.toc completed successfully.
然后就得到了这样的程序
程序运行
,免责声明:本文仅代表文章作者的个人观点,与本站无关。其原创性、真实性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容文字的真实性、完整性和原创性本站不作任何保证或承诺,请读者仅作参考,并自行核实相关内容。文章投诉邮箱:anhduc.ph@yahoo.com