0

Program shows png files, but doesn't show jpg files.
Screenshots of my program, using png/jpg files:
png https://i.stack.imgur.com/xw4vQ.png
jpg https://i.stack.imgur.com/R5T9q.png
If not compiled with py2exe, program works normally and shows all formats.
So I think it's py2exe problem.


I have in both situations this code:
(pic is QLabel, picLine is some Layout)

px = QtGui.QPixmap(pic_src)
pic.setPixmap(px)
picLine.addWidget(pic)

tried px.isNull() - returns True
so px is empty somehow
head of the python file:

# -*- coding: utf-8 -*-
from PyQt4 import QtGui, QtCore
import os, pyaudio, wave

setup.py:

from distutils.core import setup
import py2exe

setup(
    name="name",
    version="1",
    author="Columpio",
    windows=[{"script": "name.py",
              "icon_resources": [(0, "icon.ico")]}],
    data_files=[<here long list of files goes>],
    options={"py2exe": {"includes": ["os", "sip", "sys", "PyQt4", "pyaudio",
                                     "wave"],
                        "optimize": 2,
                        "bundle_files": 2
                        }
             },
    zipfile=None
    )

Sorry for awful question style -- I'm very sick now.

Columpio
  • 483
  • 1
  • 4
  • 5
  • If `px` is empty you should check `pic_src` actually pointing to the image. By the way, the images you posted are both `png`. Did you convert jpg to png? If so, did you actually **convert** it or just renamed the file name? Only renaming a file might also cause trouble. – a_guest Mar 17 '15 at 17:10
  • @a_guest these pics are screenshots :D first shows how png works, second -- how jpg not works. pic_src acrually is pointing to the image. both pics are originally in jpg and png. I thougth problem is that jpg is not raw data and png is. Then I tried bmp (raw data too) and it didn't work either. I'm totally stuck. I can find dependancy on which formats pyqt+py2exe program can read and which can't. That's why I'm asking here. – Columpio Mar 18 '15 at 11:15
  • Just to make sure we're talking about the same thing: the second pic you posted here is also png. I don't see any jpg. Apart from that: Did you try the code without compiling it with py2exe? Can you read the jpg when just running the script? For pyqt it should make no difference whether the image is in png or jpg format (implying that the image actually is in a valid state). – a_guest Mar 18 '15 at 13:14
  • @a_guest The funniest thing about that is that I really CAN use jpg, using non-compiled script. About pics: don't look at their url, but look at themselves (they are screenshots of not-working program, that's why I uploaded them). – Columpio Mar 18 '15 at 15:48
  • solution is here : [another stackOverFlow thread](http://stackoverflow.com/questions/885906/enabling-jpeg-support-for-qimage-in-py2exe-compiled-python-scripts) did not know how to mark as a duplicate – paul c Jun 02 '16 at 14:07

1 Answers1

0

Pretty sure that the problem here is that the PyQt code in the Python interpreter can see the QT image formats plugins but the executable built by py2exe can't. The plugins are in a directory plugins inside your Python site-packages directory.

This is easy to fix: the easiest way is just to copy the imageformats directory into the same directory as the executable.

I use this code in my setup.py but this is for PySide. I think the PyQt4 one is more or less the same: replace PySide with PyQt4:

ifpath = os.path.join(sys.prefix,"Lib","site-packages","PySide","plugins","imageformats")

distutils.dir_util.copy_tree(ifpath,dist_dir)
strubbly
  • 3,347
  • 3
  • 24
  • 36