Python 3.6打包成EXE可执行程序
2017-12-29 本文已影响212人
呆呆冬
1.下载pyinstaller
pip install pyinstaller
验证是否已安装,或检查已安装的版本可以使用一下命令:

2.编写程序

3.打包程序
在需要打包的文件目录下执行:
pyinstaller test1.py


打包好的文件在dist里面。但是,我们发现是里面是一个文件夹,生成了好多东西:

这是因为我们没有加参数 -F,所以打包成散包。删除刚才的散包文件,使用如下命令重新打包:
pyinstaller -F test1.py
发现dist文件夹下只有我们需要的exe文件了:

常用参数介绍
--icon=图标路径
- -F 打包成一个exe文件
- -w 使用窗口,无控制台
- -c 使用控制台,无窗口
- -D 创建一个目录,里面包含exe以及其他一些依赖性文件
- pyinstaller -h 来查看参数
如使用一下命令来改变图标:
pyinstaller -F --icon=D:\PythonProjects\demo\aa.ico test1.py
4.双击运行生成的exe文件
