2013-08-29 84 views
1

使用PyInstaller與--onefile標誌,我可以成功地建立了下面的腳本到一個.exe文件:PyInstaller --onefile拋出Qt的錯誤與大熊貓,matplotlib和sklearn

import sys 
from PyQt4 import QtGui 

class Example(QtGui.QMainWindow): 
    def __init__(self): 
     super(Example, self).__init__() 
     self.initUI() 

    def initUI(self):    
     self.statusBar().showMessage('Ready') 
     self.setGeometry(300, 300, 250, 150) 
     self.setWindowTitle('Statusbar')  
     self.show() 

def main(): 
    app = QtGui.QApplication(sys.argv) 
    ex = Example() 
    sys.exit(app.exec_()) 

if __name__ == '__main__': 
    main() 

我得到以下時的警告建立:(爲便於閱讀,我使用「PYINSTALLERDIR」替換完整路徑,即「C:\ Users \ name \ Downloads \ pyinstaller-pyinstaller-v2.0-544-g337ae69 \ pyinstaller-pyinstaller-337ae69 \」。

PYINSTALLERDIR>pyinstaller.py --onefile --log-level=WARN MainWindowHello.py 
1306 WARNING: library python%s%s required via ctypes not found 
1468 INFO: Adding Microsoft.VC90.CRT to dependent assemblies of final executable 
2957 WARNING: library python%s%s required via ctypes not found 

但輸出的14 MB .exe運行良好並顯示一個Qt窗口但是,當我嘗試添加熊貓,matplotlib或sklearn,我碰到Qt的問題。

添加任何import matplotlibimport sklearn排隊我的劇本的3給了我這些警告,當建築:

PYINSTALLERDIR>python pyinstaller.py --onefile --log-level=WARN MainWindowHello.py 
1371 WARNING: library python%s%s required via ctypes not found 
1528 INFO: Adding Microsoft.VC90.CRT to dependent assemblies of final executable 
3051 WARNING: library python%s%s required via ctypes not found 
27108 INFO: Adding Microsoft.VC90.MFC to dependent assemblies of final executable 
33329 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable 

當我嘗試運行.exe文件產生(44 MB的matplotlib,87 MB的sklearn)不顯示Qt的窗口,我得到這個錯誤信息:

WARNING: file already exists but should not: C:\Users\name\AppData\Local\Temp\_MEI75002\Include\pyconfig.h 
Traceback (most recent call last): 
    File "<string>", line 2 in <module> 
    File "PYINSTALLERDIR\PyInstaller\loader\pyi_importers.py", line 409, in load_module 
ImportError: could not import module 'PySide.QtCore' 

隨着import pandas在第3行,我得到同樣的警告(以及警告有關libzmq.pyd,但我已經有工作計劃早一點它們) 。當我嘗試運行119 MB .exe文件,程序崩潰並引發以下錯誤:

WARNING: file already exists but should not: C:\Users\name\AppData\Local\Temp\_MEI85162\include\pyconfig.h 
Sub class of QObject not inheriting QObject!? Crash will happen when using Example. 

我試圖與這兩個PyInstaller 2.0和開發人員版。當使用默認的--onedir而不是--onefile時,所有這三種情況都可以正常工作。任何人都可以幫我弄清楚使用--onefile時會出現什麼錯誤?

更新:我試着在PyInstaller 2.1中構建大熊貓,當使用--onefile時我仍然得到相同的錯誤。再說一遍,當不使用--onefile時,所有東西都可以工

回答

1

我與我正在導入PyQt4以及導入PySide的一些模塊的腳本有同樣的問題。 PyInstaller在--onedir選項(默認)下工作良好,但在使用--onefile選項時,我得到了ImportError: could not import module 'PySide.QtCore'

閱讀this之後,我嘗試添加'PySide'作爲一個在我的規格文件中排除強制獨家使用PyQt4的和exe文件,現在運行正常。你列出的模塊應該可以在PyQt4上正常工作,所以它也應該可以解決你的問題。

另外,雖然這不是一個大問題,但file already exists警告的解決方案描述爲here。只需a = Analysis...後添加在規範文件中的這些行刪除導致警告的重複:

for d in a.datas: 
    if 'pyconfig' in d[0]: 
     a.datas.remove(d) 
     break