2

For some reason on my system (Windows XP 32-bit, Python 2.6) PyQt is able to display gifs perfectly when run in the python interpreter, but when I run it through py2exe, they no longer display.

I've tried everything I've googled: copying the gif DLLs from PyQt into an imageformats/ folder, setting up a qt.conf (as another stackoverflow thread suggested), done a setLibraryPaths to where the imageformat DLLs were, copied the setup file from http://wiki.wxpython.org/py2exe-python26 .

Nothing seems to work -- what on earth could I be doing wrong?

  • Convert the gif(s) to png(s) and in your application use the pngs instead of gifs. I faced the same issue but couldn't explore the cause of the issue. Using pngs instead fixed the issue for me. HTH. – sateesh Jan 31 '11 at 09:34
  • 1
    You might want to look at this existing question which tries to solve the problem for jpegs: http://stackoverflow.com/questions/885906/enabling-jpeg-support-for-qimage-in-py2exe-compiled-python-scripts – xioxox Feb 03 '11 at 12:25

3 Answers3

2

I'm not sure how you even managed to compile PyQt with py2exe; I had no success, and switched to pyinstaller.
Py2exe wasn't cooperating well PyQt and refused to compile depending on what widgets were featured.

I'd recommend switching to pyinstaller for compiling PyQt; see if it allows what you want in this case

Anti Earth
  • 4,671
  • 13
  • 52
  • 83
0
from distutils.core import setup
import py2exe

DATA=[('imageformats',['C:\\Python26/Lib/site-packages/PyQt4/plugins/imageformats/qjpeg4.dll',
    'C:\\Python26/Lib/site-packages/PyQt4/plugins/imageformats/qgif4.dll',
    'C:\\Python26/Lib/site-packages/PyQt4/plugins/imageformats/qico4.dll',
    'C:\\Python26/Lib/site-packages/PyQt4/plugins/imageformats/qmng4.dll',
    'C:\\Python26/Lib/site-packages/PyQt4/plugins/imageformats/qsvg4.dll',
    'C:\\Python26/Lib/site-packages/PyQt4/plugins/imageformats/qtiff4.dll'
    ])]
setup(windows=[{"script":"your_python_script.py"}], 
    data_files = DATA,
    options={"py2exe":{
        "includes":["sip", "PyQt4.QtNetwork", "PyQt4.QtWebKit", "PyQt4.QtSvg" ],
        "bundle_files":3,
        "compressed":True,
        "xref":True}}, 
    zipfile=None)
0

Just in case anyone is in this situation, I found the solution. These is what you need to do when compiling with py2exe so your image files are shown:

  • All the image files (gif, png, jpg) need to be copied to the dist folder
  • Qt dll files need to be copied from Qt installation folder to dist\imageformats

For the dll files you need to set this on your setup.py file:

windows = [{
            "script":"yourPythonScript.py",
            "icon_resources": [(1, "nameOfIcoFile.ico")],
            "dest_base":"nameOfExeFile"
            }],
            data_files = [
                ('imageformats',
                [r'C:\Python27\Lib\site-packages\PyQt4\plugins\imageformats\qico4.dll',
                r'C:\Python27\Lib\site-packages\PyQt4\plugins\imageformats\qgif4.dll'
                ])],
)
slfan
  • 8,950
  • 115
  • 65
  • 78
Miguel
  • 1