python - py2exe 访问 'other_resources'

标签 python py2exe

因此,使用 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/

相关文章:

python - Archlinux 上用于 Matplotlib 的 PyQt4、PyQt5 或 PySide

python - 在 MySQL 中快速插入 10 亿行

python - 从 Pandas 数据框中的每个单元格中删除列表

python - 应用程序的外观 - Py2exe/wxPython

python - 导入错误 : no module named py2exe

python - 根据日期 Pandas 有效地创建行

python - PyQt:当单元格进入 QCalendarWidget 时发出信号

python - PyInstaller/Py2exe - 在单文件编译中包含带有第三方脚本的 os.system 调用

python - Django翻译和py2exe

python - wxPython和py2app,CreateActCtx错误0x00000008(没有足够的可用磁盘空间)