2010-02-05 13 views
0

要在PyQT應用程序中啓用jpeg支持,您必須手動包含qjpeg4.dll
當最終的exe文件沒有將dll和pyd文件捆綁在一起時,它工作正常。例如 與py2exe,你可以做到以下幾點:pyqt jpeg支持不以捆綁形式工作

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) 

但是,如果你做同樣的事情,而你在exe文件捆綁的DLL(使用"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 

如何正確捆綁應用程序?

回答

0

嘗試增加pyqt4作爲一攬子迫使py2exe包括在您構建了從PyQt的,就像這樣:

options={"py2exe":{ 
     "includes":["sip"], 
     "excludes":MODULE_EXCLUDES, 
     "packages":["PyQt4"], 
     "bundle_files":1, 
     "compressed":False, 
     "xref":True}} 
+0

修改pyqt - > PyQt4有一個有效的包名稱,但失敗了。顯然PyQt4不喜歡被包含這種方式。它失敗: 錯誤:編譯'C:\ Python26 \ lib \ site-packages \ PyQt4 \ uic \ port_v3 \ proxy_base.py' 失敗 SyntaxError:無效語法(proxy_base.py,第4行) – shodanex 2010-02-08 14:53:41

+0

這是一個proxy_base.py中的錯誤?將proxy_base添加到您的Excludes並查看它是否構建 – 2010-02-08 15:30:26

2

我有同樣的問題,據我所知,py2exe提供了線索: http://www.py2exe.org/index.cgi/Py2exeAndPyQt

它顯示爲: ......所以您需要將文件夾PyQt4 \ plugins \ imageformats複製到\ imageformats。 ....... 這不適用於上的bundle_files。 ... *這也適用於bundle_files,但您需要從捆綁包中排除Qt DLL(使用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

這一切