如何使用 cx_Freeze 制作可执行的 python 程序
How to use cx_Freeze to make an executable python program
我下载了 cx_Freeze,因为我正在尝试制作一个 .exe 文件与我的排共享,并且我一直在通读 docs as well as scrolling through cx_Freeze tutorial。在关注了这两个之后,我仍然不知道为什么这对我不起作用。我在 Python 3.6.2 上,我有直接设置到命令行的路径。
我尝试在桌面上使用 setup.py 和 Julian 日期 2.py 启动,并尝试将它们添加到同一文件夹,但无论我尝试什么,当我键入 python setup.py build
、python: can't open file 'setup.py': [Error2] no such file or directory or file exsists
。下面是我的 setup.py 代码。
from cx_Freeze import setup, Executable
setup(name = "Julian date 2" ,
version = "0.1" ,
description = "" ,
executables = [Executable("Julian date 2.py")])
我 运行 遇到的另一个问题是尝试输入 cxfreeze Julian date 2.py --target-dir dist
我收到错误 'cxfreeze' is not recognized as an internal or external command, operable program or batch file.
当您键入 python setup.py build 时,您应该位于 setup.py 的目录中,而不是其他任何地方。所以使用命令 cd 到达那里。
cx_freeze 不在您的路径变量中,因此 cxfreeze Julian date 2.py --target-dir dist 将不起作用,您必须将其添加到您的路径中(不知何故)[不推荐]
希望对您有所帮助。
P.S。
executables = [Executable("Julian date 2.py")]) 也有基础。如果你想要一个控制台应用程序:
可执行文件 = [可执行文件("Julian date 2.py",base='None')])
windows 的 Gui:
可执行文件 = [可执行文件("Julian date 2.py",base='Win32GUI')])
并且您忘记了 setup() 中的 exe 选项。我建议在 cx_freeze doxs:
上调整 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"
setup( name = "name",
version = "0.1",
description = " ",
options = {"build_exe": build_exe_options},
executables = [Executable("file.py", base=base)])
我解决了第一个问题,我的文件被命名为 'setup.py' 而不是应该的 'setup'...名称必须是设置,扩展名.py
知道这是愚蠢的,几个小时后,这就是问题所在...
我下载了 cx_Freeze,因为我正在尝试制作一个 .exe 文件与我的排共享,并且我一直在通读 docs as well as scrolling through cx_Freeze tutorial。在关注了这两个之后,我仍然不知道为什么这对我不起作用。我在 Python 3.6.2 上,我有直接设置到命令行的路径。
我尝试在桌面上使用 setup.py 和 Julian 日期 2.py 启动,并尝试将它们添加到同一文件夹,但无论我尝试什么,当我键入 python setup.py build
、python: can't open file 'setup.py': [Error2] no such file or directory or file exsists
。下面是我的 setup.py 代码。
from cx_Freeze import setup, Executable
setup(name = "Julian date 2" ,
version = "0.1" ,
description = "" ,
executables = [Executable("Julian date 2.py")])
我 运行 遇到的另一个问题是尝试输入 cxfreeze Julian date 2.py --target-dir dist
我收到错误 'cxfreeze' is not recognized as an internal or external command, operable program or batch file.
当您键入 python setup.py build 时,您应该位于 setup.py 的目录中,而不是其他任何地方。所以使用命令 cd 到达那里。
cx_freeze 不在您的路径变量中,因此 cxfreeze Julian date 2.py --target-dir dist 将不起作用,您必须将其添加到您的路径中(不知何故)[不推荐]
希望对您有所帮助。
P.S。 executables = [Executable("Julian date 2.py")]) 也有基础。如果你想要一个控制台应用程序: 可执行文件 = [可执行文件("Julian date 2.py",base='None')]) windows 的 Gui: 可执行文件 = [可执行文件("Julian date 2.py",base='Win32GUI')])
并且您忘记了 setup() 中的 exe 选项。我建议在 cx_freeze doxs:
上调整 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"
setup( name = "name",
version = "0.1",
description = " ",
options = {"build_exe": build_exe_options},
executables = [Executable("file.py", base=base)])
我解决了第一个问题,我的文件被命名为 'setup.py' 而不是应该的 'setup'...名称必须是设置,扩展名.py
知道这是愚蠢的,几个小时后,这就是问题所在...