我有一个 Python 脚本,我想将其编译成单个可执行文件,我读到 PyInstaller 是最佳选择,但不幸的是 CX_Freeze 是我发现的唯一可以与 Python 3.6 一起使用的编译器。
有没有办法用 CX_Freeze 来做到这一点?
最佳答案
首先您必须有 cx_freeze 5.0.1,因为它支持 python 3.6 。
然后,它就像任何 3.X 版本一样。 将此代码放入 setup.py 文件中并替换:
"prog.py"
使用您的主脚本名称。
小心,不要忘记,如果你要进入控制台,它应该是
if sys.platform == "win32":
base = "console"
这是代码:
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 = "my prog",
version = "1.0",
description = "My application!",
options = {"build_exe": build_exe_options},
executables = [Executable("prog.py", base = base)])
打开命令提示符写入:
cd your directory path
python setup.py build
关于python - 在 CX_Freeze 中从 Python 3.6 脚本创建单个 exe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43272036/