Python cx_freeze 设置脚本无法工作
我有一个Python脚本想要打包成可执行文件。我使用了cx_freeze
这个工具,并且运行了它。生成的.exe
文件运行得很好,但在这个打包后的脚本中,我打开了一个.html
文件。当文件打开时,浏览器给我报错:“文件未找到:Firefox无法在/c:/blah/blah/blah/somefile.html找到文件
”。
我理解这是因为cx_freeze
让我的操作系统在Linux和Windows之间搞混了。不过,我不太确定是不是这个原因,因为我在我的设置文件中有以下代码:
if sys.platform == "win32":
base = "Win32GUI"
我的整个设置文件是:
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 = "someexe",
version = "0.1",
description = "someexe description",
options = {"build_exe": build_exe_options},
executables = [Executable("someexe.py", base=base)])
从cx_freeze的文档页面复制过来的,并根据我的需要进行了修改。
1 个回答
0
你应该用 os.chdir('C:\path\to\dir')
,而不是 os.chdir('C:/path/to/dir')
。这是你代码里的一个错误,不是你 cx_freeze 设置文件的问题。