pyqt打包形式下不支持jpeg
要在PyQT应用程序中启用jpeg支持,你需要手动包含一个叫做qjpeg4.dll
的文件。
当这个dll文件和pyd文件没有一起打包到最终的exe文件里时,它工作得很好。比如说,使用py2exe时,你可以这样做:
DATA=[('imageformats',['C:\\Python26/Lib/site-packages/PyQt4/plugins/imageformats/qjpeg4.dll'])]
setup(console=[{"script":"cycotic.py"}],
data_files = DATA,
options={"py2exe":{
"includes":["sip"],
"excludes":MODULE_EXCLUDES,
"bundle_files":3,
"compressed":False,
"xref":True}},
zipfile=None)
但是,如果你做了同样的事情,把dll文件打包进exe里(使用"bundle_files":1
),就会出现以下错误信息:
QObject::moveToThread: Current thread (0x3a16608) is not the object's thread (0x
2dddaf8).
Cannot move to target thread (0x2dddaf8)
QObject::moveToThread: Current thread (0x3a16608) is not the object's thread (0x
2dddaf8).
Cannot move to target thread (0x2dddaf8)
QObject::moveToThread: Current thread (0x3a16608) is not the object's thread (0x
2dddaf8).
Cannot move to target thread (0x2dddaf8)
QPainter::begin: Paint device returned engine == 0, type: 3
QPainter::end: Painter not active, aborted
QPixmap::scaled: Pixmap is a null pixmap
我该如何正确地打包这个应用程序呢?
2 个回答
0
试着把 pyqt4
加入到你的包里,这样可以强制 py2exe 把 PyQT 的所有内容都包含到你的程序构建中,像这样:
options={"py2exe":{
"includes":["sip"],
"excludes":MODULE_EXCLUDES,
"packages":["PyQt4"],
"bundle_files":1,
"compressed":False,
"xref":True}}
2
我也遇到了同样的问题,听说py2exe给出了一些提示:
http://www.py2exe.org/index.cgi/Py2exeAndPyQt
内容是:......你需要把文件夹 PyQt4\plugins\imageformats 复制到 \imageformats。....... 但是如果开启了 bundle_files,这样做是行不通的。
...... *如果开启了 bundle_files 也是可以的,但你需要把 Qt 的 DLL 文件从 bundle 中排除(使用 dll_excludes 选项),然后通过其他方式(比如 data_files)把它们添加到可执行文件所在的目录中。*
以下是我的设置选项,像这样:
zipfile=None,
options = { "py2exe" :{
"compressed":1,
"includes": my_includes,
"packages": my_packages,
"optimize":2,
"bundle_files":1,
"dll_excludes":["QtCore4.dll","QtGui4.dll","QtNetwork4.dll"]
}}
所以 dist 文件夹里包含这些文件(在我的情况下):
- imageformats(文件夹,包含处理图像的 qt 插件 dll)
- QtCore4.dll
- QtGui4.dll
- QtNetwork4.dll
- MyExeFile.exe
- w9xpopen.exe
就这些了。