今天才知道,原来可以在没安装 python 环境的 windows 上,用 pyinstaller 生成一个 py 对应的 exe,双击它来运行 py 程序。
pyInstaller 的下载页: http://www.pyinstaller.org/downloads.html
编译方法:
在 cmd 里,进入 d:\pyStuff\PyInstaller-3.5 文件夹,运行:
python pyinstaller.py -F -w D:\workspace\configFile.py
参数说明:
-F, --onefile py 代码只有一个文件
-D, --onedir py 代码放在一个目录中(默认是这个)
-w, --windowed exe 运行时没有 console
-c, --nowindowed exe 运行时有 console (默认是这个)
pyinstaller 编译 exe 的脚本:
新建一个 .bat 文件,写以下内容。双击这个 bat 文件,就能编译出来 exe 了。
编译结果在 d:\pyStuff\PyInstaller-3.5\GetArgs\dist 里。
@echo off
d:
cd d:\pyStuff\PyInstaller-3.5
python pyinstaller.py -F -w D:\workspace\pyTest\GetArgs.py