py2exe bundle_files=1或2失败

0 投票
1 回答
1218 浏览
提问于 2025-04-16 10:10

我的应用程序使用了QGraphicsPixmapItem,为了让它能够加载jpeg文件,我把qjpeg4.dll放在了'dist'目录下的'imageformats'子目录里。
这样做是有效的,但只有当'bundle_files'选项设置为3时才可以。
如果我把它设置为1或2,qt4(pyqt4)就找不到需要的dll文件了,这样QGraphicsPixmapItems就看不见了。

setup.py:

from distutils.core import setup
import py2exe

setup(
    options = {'py2exe': {'bundle_files': 1}},
    description = "",
    name = "name",
    windows = ["mainwindow.py"],
    zipfile=None,
    )

1 个回答

0

你可以通过以下方式让py2exe包含这个dll文件:

setup(
      # other options,
      data_files=[('imageformats', 'qjpeg4.dll'),
      #other options
     )

为了将来参考,data_files应该像这样设置(据我所知):

data_files = [ (dir1, [file1, file2, ...]), (dir2, [file3, file4, ...]), ...]

编辑 1:你可以尝试使用这样的目录结构(来源):

  • yourapp.exe
  • [qt.conf](可选?见下文)
  • plugins/
    • imageformats/
      • qjpeg4.dll

如果这样还不行,这里建议使用一个看起来像这样的qt.conf文件:

[Paths]
Plugins = <directory containing the imageformats directory>

只要核心dll QtCore4.dll正确包含,这个方法应该没问题(因为它需要这个.dll来解析你的qt.conf文件)。

撰写回答