![e75a4e8703e8ed16f82e8a88d4e70898.png](https://i-blog.csdnimg.cn/blog_migrate/61e8af8405095e8911eff6b0d3f36a91.jpeg)
将Python程序打包为exe文件,需要使用到的工具是pyinstaller
pyinstaller是一个多平台的Python程序打包为exe的免费工具
安装pyinstaller:
在Windows中,pyinstaller依赖pywin32,所在如果打包有问题请先安装pywin32模块,安装命令:pip install pywin32
![209476d3c987fe60b45a7ead718e3d25.png](https://i-blog.csdnimg.cn/blog_migrate/68b078991294df7ac1a769b6a7e35f4f.jpeg)
安装pywin32
使用pip安装pyinstaller,安装命令:pip install pyinstaller
![ec4aa49ec1968d5b88957cdcf9e159ca.png](https://i-blog.csdnimg.cn/blog_migrate/b57bdb8b117fc8671a69fd43c5011cae.jpeg)
安装pyinstaller
pyinstaller的使用
打包命令:pyinstaller -F py文件路径
打包成功后dist文件夹下就是exe了
其他参数的使用:
提示:-i 可以替换默认ico图标
命令:pyinstaller -F -i ico图片路径 py文件路径
![604d2d301b9c4ab5bd8dc6bc12007e15.png](https://i-blog.csdnimg.cn/blog_migrate/ea504ae0e21f8ebcb4fe22212390ca61.jpeg)
指令参数
实战
接下来我们操作一个文件
![c0da9bce0614406af7a83d05221d6ac2.png](https://i-blog.csdnimg.cn/blog_migrate/87bc0f77edbe81cf576a211eeb6eecfa.jpeg)
打包
打包成功之后,在dist文件夹下会有我们的exe文件,点击运行即可
![79e4edc9c2f508c4b2ea4192d2fc14aa.png](https://i-blog.csdnimg.cn/blog_migrate/c9390de9139fb9100b2da8615b15c8fb.jpeg)
运行成功
然后你就可以将程序复制到任何电脑了,不管有没有安装python环境都可以运行。
到此我们的程序就结束了。有些小伙伴可能会用中文命名,这样的话可能会报UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position 168: illegal multibyte sequence 的错误。请把文件名字改为英文就不会报错了。
文件资料教程我都准备好了。私信学习资料就能获取到学习资料,在学习中遇到的问题也可以咨询我。