docs:http://cx-freeze.readthedocs.io/en/latest/distutils.html
download:https://pypi.python.org/pypi/cx_Freeze/
在python中比较常用的python转exe方法有三种,分别是cx_freeze,py2exe,PyInstaller。py2exe恐怕是三者里面知名度最高的一个,但是同时相对来说它的打包质量恐怕也是最差的一个。pyinstaller打包很好,但是操作工序较为复杂。
cx_freeze打包的exe需要和依赖库放在一个文件夹
首先:cx_freeze下载地址: http://sourceforge.net/projects/cx-freeze/files/
第一步:检查cx_freeze是否安装正确。
进入Python的Scripts文件夹
>cxfreeze -h
显示用法,则安装正确
正式开始打包,命令为:
cxfreeze hello.py --target-dir dist
加上红色参数可以隐藏控制台
cxfreeze hello.py --base-name="win32gui"
-
只能指定一个要打包的模块,也就是启动模块
-
所有.py文件都不能有中文字符,否则会出现编码异常。
-
发布后,可执行文件执行路径不能有中文(最好也不要有空格)。
- 启动执行的文件中不要有下面这种判断,否则可执行文件执行会没有任何效果。
if __name__ == "__main__":
main()
2,用setup.py安装
import sys
from cx_Freeze import setup, Executable
# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {"packages": ["os"], "excludes": ["tkinter"]}
# GUI applications require a different base on Windows (the default is for a
# console application).
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup( name = "gui",
version = "8.1",
description = "application!",
options = {"build_exe": build_exe_options},
executables = [Executable("fun.py", base=base, targetName = 'launch.exe',icon = "qq.ico")])
出处:http://keliang.blog.51cto.com/3359430/661884