python打包exe
2022-10-18 本文已影响0人
小鬼hui辉
第一次使用python做自动化,整理了一下打包exe的过程,用pyinstaller打包,首先是安装
1、安装pyinstaller
首先安装pyinstaller,使用安装命令:pip3 install pyinstaller
![](https://img.haomeiwen.com/i12880527/5ce0439ec50d409b.png)
2、通过pyinstaller将.py文件打包成exe
先进入到要打包的.py文件的目录下,执行命令:pyinstaller-F w.py 或者 pyinstaller-F -w w.py , 加上-w再执行的时候黑色控制台会消失
![](https://img.haomeiwen.com/i12880527/e0e3d489057c7141.png)
![](https://img.haomeiwen.com/i12880527/21f5126b810e2107.png)
3、执行完成后,会在目录下有个dist文件,里面会有个exe程序,点击后可直接执行。
![](https://img.haomeiwen.com/i12880527/0b292fcdb7a182a9.png)
4、打包的时候也可以根据自己的需要更换打包后的图标,执行命令如下:pyinstaller -F -i xx.ico -w w.py (图片我是放在了项目根目录下面)
![](https://img.haomeiwen.com/i12880527/9fded50d326c0ab1.png)
要说明的是格式一定要对,只支持ico 16*16格式的图片,我开始手动把后缀修改成ico的执行报错如下:
![](https://img.haomeiwen.com/i12880527/acc3554dd9dbee9e.png)