因此,使用 py2exe,您可以在库 zip 文件中添加其他数据,现在我想知道,您如何访问这些数据,您是否需要从 zip 文件中读取它,或者您是否可以像访问任何其他文件一样访问它?或者也许有另一种方式来访问它。
最佳答案
我个人从未使用过压缩文件。相反,我传递我的程序在设置方法中使用的数据文件并使用 bundle_files 选项(如 this 页面底部所述)。例如,我使用此调用创建的程序
setup(name = "Urban Planning",
windows = [{'script': "main.py", "dest_base": "Urban_Planning"}],
options = opts, # Dictionary of options
zipfile = None, # Don't create zip file
data_files = Mydata_files) # Add list of data files to folder
在它之前还有一 block ,其中添加了配置文件和用户界面的一些图像,如下所示
Mydata_files = [] # List of data files to include
# Get the images from the [script root]/ui/images/ folder
for files in os.listdir(sys.path[0] + '/ui/images/'):
f1 = sys.path[0] + '/ui/images/' + files
if os.path.isfile(f1): # This will skip directories
f2 = 'ui/images', [f1]
Mydata_files.append(f2)
# Get the config file from the [script root]/Configs folder
Mydata_files.append(('Configs', [sys.path[0] + '/Configs/defaults.cfg']))
这样我就可以像在空闲或命令提示符下运行脚本时那样调用我的配置文件,并且我的 UI 图像可以正确显示。
关于python - py2exe 访问 'other_resources',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3414616/