当我从A.exe(位于c:/my_software/FOLDER_A/A.exe中)运行B.exe(位于c:/my_software/FOLDER_B/B.exe中)时,两者均使用cx_Freeze,B.exe构建(称为)尝试在B.exe文件夹中进行搜索时尝试在A.exe文件夹(调用方)中找到他的模块(例如IMAGE_B.png)。我认为这是由于cx_Freeze的setup.py中的一些错误代码导致的。
我在脚本中使用函数os.getcwd()来获取每个.exe中的根路径
这是我的setup.py,我用来同时构建.exe(A和B)
import os
from cx_Freeze import setup, Executable
import sys
os.environ['TCL_LIBRARY'] = r'c:\python\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'c:\python\tcl\tk8.6'
buildOptions = dict(packages = ["tkinter","os"],
excludes = [],
include_files [r'c:\python\DLLs\tcl86t.dll',
r'c:\python\DLLs\tk86t.dll',
'A.png','icono.ico'])
executables = [Executable('A.py',
base="Console",
icon = "icono.ico")]
setup(name='A',version = '1',
description = 'program A',
options = dict(build_exe = buildOptions),
executables = executables)
答案 0 :(得分:0)
请参见cx_Freeze
文档how to use data files。它提供了以下代码示例:
def find_data_file(filename):
if getattr(sys, 'frozen', False):
# The application is frozen
datadir = os.path.dirname(sys.executable)
else:
# The application is not frozen
# Change this bit to match where you store your data files:
datadir = os.path.dirname(__file__)
return os.path.join(datadir, filename)
请注意,cx_Freeze
版本5.1.1(当前版本)会将软件包冻结到构建目录的lib
子目录中,而主脚本本身将冻结在构建目录中。您可能需要相应地修改上面的代码示例。