2
因此,使用py2exe你可以在库zip文件中添加额外的数据,现在我想知道,你如何访问这些数据,你需要从zip文件中读出它还是只能访问它像其他文件一样?或者也许有另一种方式来访问它。py2exe访问'other_resources'
因此,使用py2exe你可以在库zip文件中添加额外的数据,现在我想知道,你如何访问这些数据,你需要从zip文件中读出它还是只能访问它像其他文件一样?或者也许有另一种方式来访问它。py2exe访问'other_resources'
我个人从未使用过zipfile。相反,我传递了我的程序在安装方法中使用的数据文件,并使用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
还收到了一张,其中一个配置文件和一些图像用户界面添加这样
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图像正确显示。
嗯,我更喜欢把它保存在一个文件中,更容易制作二进制差异更新和东西。 – 2010-08-05 19:29:12