For some reason on my system (Windows XP 32-bit, Python 2.6) PyQt is able to disp开发者_如何学JAVAlay 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?
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
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)
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'
])],
)
精彩评论