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

yipeiwu_com5年前Python基础

原文提到的要点:

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

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

相关文章

python 比较2张图片的相似度的方法示例

本文介绍了python 比较2张图片的相似度的方法示例,分享给大家,具体如下: #!/usr/bin/python # -*- coding: UTF-8 -*- import cv...

Python 词典(Dict) 加载与保存示例

Dict的加载: import json def load_dict(filename): '''load dict from json file''' with open(f...

使用PyTorch实现MNIST手写体识别代码

实验环境 win10 + anaconda + jupyter notebook Pytorch1.1.0 Python3.7 gpu环境(可选) MNIST数据集介绍 MNIST 包...

Python+Selenium自动化实现分页(pagination)处理

场景 对分页来说,我们最感兴趣的是下面几个信息 总共有多少页 当前是第几页 是否可以上一页和下一页 代码 下面代码演示如何获取分页总数及当前页数、跳转到指定页数 #coding:u...

Python 使用 prettytable 库打印表格美化输出功能

Python 使用 prettytable 库打印表格美化输出功能

pip install prettytable 每次添加一行 from prettytable import PrettyTable # 默认表头:Field 1、Field 2....