欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

详解Python3.6的py文件打包生成exe

程序员文章站 2023-11-04 11:34:58
原文提到的要点: 1. python版本32位 (文件名为 python-3.6.1.exe) 2. 安装所有用到的模块(原文博主用的是openpyxl,我用到的有ur...

原文提到的要点:

1. python版本32位 (文件名为 python-3.6.1.exe)

2. 安装所有用到的模块(原文博主用的是openpyxl,我用到的有urllib中的request\config\data)

3. 下载替换pyinstaller(下载pyinstaller-develop.zip,复制其中的pyinstaller文件夹)

4. 在控制台生成exe

操作过程记录如下:

c:\python\scripts>pip install request
c:\python\scripts>pip install config
c:\python\scripts>pip install data
c:\python\scripts>pyinstaller.exe -f structs2.py

生成成功界面内容:

24957 info: checking exe
24957 info: building exe because out00-exe.toc is non existent
24957 info: building exe from out00-exe.toc
24958 info: appending archive to exe c:\python\scripts\dist\structs2.exe
24975 info: building exe from out00-exe.toc completed successfully.

之前失败了很多次,python 3 转 exe 失败原因总结:

1. python开发环境版本、环境变量不一致。之前错误的安装了(python-3.6.2rc1.exe)

2. 注意版本,之前尝试了多个版本,最后全部卸掉重新安装才成功

3. python包要安装全,之前我没有装request \config等包,也可能是失败原因之一

曾有失败,内容如下:

usage: setup.exe [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
or: setup.exe --help [cmd1 cmd2 ...]
or: setup.exe --help-commands
or: setup.exe cmd --help

解决方法是重新清理安装开发环境。终于成功。

详解Python3.6的py文件打包生成exe