问题描述:

My application uses QGraphicsPixmapItem, and to make it able to load jpeg files I've placed qjpeg4.dll under 'imageformats' subdirectory in the 'dist' directory.

It works, but only as long as 'bundle_files' option is set to 3.

If I set it to 1 or 2, qt4 (pyqt4) is no longer able to find needed dlls, and so QGraphicsPixmapItems is not visible.

setup.py:

from distutils.core import setup

import py2exe

setup(

options = {'py2exe': {'bundle_files': 1}},

description = "",

name = "name",

windows = ["mainwindow.py"],

zipfile=None,

)

网友答案:

You should be able to convince py2exe to include the dll by using:

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

For future reference, data_files should look like this (afaik):

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

EDIT 1: You could try using a directory structure like this (source):

  • yourapp.exe
  • [qt.conf] (optional? see lower down)
  • plugins/
    • imageformats/
      • qjpeg4.dll

And if that doesn't work, here suggests using a qt.conf file that looks like this:

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

Which apparently should work fine so long as the core dll QtCore4.dll has been included correctly (as it needs this .dll to interpret your qt.conf file).

相关阅读:
Top