1
我有一个Python脚本,我想编译成单个可执行文件,我已经读过PyInstaller是最好的选择,但不幸的是CX_Freeze是我发现的唯一编译器与Python 3.6一起工作。在CX_Freeze中创建单个的Python 3.6脚本
有没有办法用CX_Freeze做到这一点?
我有一个Python脚本,我想编译成单个可执行文件,我已经读过PyInstaller是最好的选择,但不幸的是CX_Freeze是我发现的唯一编译器与Python 3.6一起工作。在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"
这里不forgit是代码:
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)])
打开命令prompot写:
cd your directory path
python setup.py build
我按照这个步骤,但我得到了下面的错误,当通过cmd运行我的exe文件时 '导入错误:缺少必需的依赖[ 'numpy的']' 但是当我在我的空闲导入numpy的,它工作正常 '>>>进口numpy' ''>>> – pyd