tags:

views:

165

answers:

1

In a PyQT4 program, I have a QLabel displaying an image with the following code :

in the init code :

Image=QImage(som_path_from_a_fileDialog)

in the resize method :

pixmap = QPixmap.fromImage(Image)
pixmap = pixmap.scaled(self.display.size())
self.display.setPixmap(pixmap)

When I execute my script with python, it works fine, and I can display .bmp and JPEG files. If I compile it using py2exe however, I will only be able to display .bmp files. JPEG File display will fail with :

QPainter::begin: Paint device returned engine == 0, type: 3
QPainter::end: Painter not active, aborted
QPixmap::scaled: Pixmap is a null pixmap

EDIT : It is a duplicate of this question

+1  A: 

Support for many image formats in recent versions of PyQt4 available via plugins. These plugins could be found in your C:\PythonXY\Lib\site-packages\PyQt4\plugins\imageformats directory. You should copy imageformats directory to the directory with your exe. Please note, that you need to have imageformats directory right along the your pyapp.exe. Or you should put in the same directory where is your pyapp.exe located special qt.conf where you can specify the path to the image plugins, e.g.

[Paths]
Plugins = Library\plugins

Here is example of the code to copy sqlite plugin (it's not for images, but you will get the idea) when I built my exe:

from distutils.core import setup
import py2exe
import os, sys
import PyQt4

setup(options = {"py2exe": {"includes": ["sip"]}},
     data_files=[('sqldrivers', [os.path.join(os.path.dirname(PyQt4.__file__), 
                                              'plugins', 
                                              'sqldrivers', 
                                              'qsqlite4.dll')])],
     windows = ["myapp.py"],
     )
bialix
It works, but not when I bundle files together, see http://stackoverflow.com/questions/2206737/pyqt-jpeg-support-not-working-in-bundled-form
shodanex