软硬件环境
- Windows 7
- Python 3.4.2
- PyQt5
- Py2exe
前言
Py2exe
打包firstPyQt5工程
编写打包脚本
新建一个python文件setup.py,添加内容
from distutils.core import setup
import py2exe
import sys
py2exe_options = {
"includes": ["sip"],
"dll_excludes": ["MSVCP90.dll",],
"compressed": 1,
"optimize": 2,
"ascii": 0,
"bundle_files": 1,
}
setup(
name = '第一个PyQt5程序',
version = '1.0',
windows = ['main.py'],
zipfile = None,
options = {'py2exe': py2exe_options}
)
各个配置选项基本上都能看懂,就不说了
运行打包命令
进入到你的工作目录,在cmd里执行
python setup.py py2exe
py2exe_cmd
执行完毕后,会在firstPyQt5文件下生成dist文件夹,进去执行生产的exe文件。很不幸,报错了
py2exe_error_01为了解决这个问题,我们添加一个环境变量
py2exe_variant再次执行exe,就看到我们预期的效果。
py2exe_result