3种工具为:py2exe、cx_Freeze、pyinstaller 可使用 pip 安装 , 使用示例如下:
1.py2exe
编写脚本,命名为setup_py2exe.py:
from distutils.core import setup
import py2exe
options={"py2exe":
{
"compressed":1,
"optimize":2,
"bundle_files":1
}
}
setup(
version="8.8.8",
description="xxx",
name="xxx",
options=options,
zipfile=None,
console=[{"script":"script.py", "icon_resources": [(1, "img.ico")]}],
)
使用方法:切换至脚本所在目录执行命令:
python setup_py2exe.py py2exe
2.cx_Freeze
import sys
from cx_Freeze import setup, Executable
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup(
name = "gui",
version = "1.0",
description = "client tools",
executables = [Executable("gui.py",base = base,icon = "img.ico")])
使用方法:
python setup_py2exe.py build
3.pyinstaller
使用方法:
pyinstaller -F -w E:/Temp/test.py(文件路径)
#如果python 安装路径中有空格 会报 failed to create process.
#方法1:直接用 Python 运行 script
# "C:\Program Files\Python 3.5\Scripts\pyinstaller-script.py" -F -w E:/Temp/test.py
#方法2:
#打开 pyinstaller-script.py 文件修改第一行路径加上引号,如:
#!"C:\Program Files (x86)\Python35-32\python.exe" <←←←←←這個 shebang line 有問題, 要补上前后引号
# EASY-INSTALL-ENTRY-SCRIPT: 'PyInstaller==3.1.1','console_scripts','pyinstaller'