2011-12-18 34 views
4

我想編譯PyQt程序使用PyInstaller 1.5。當我使用--onedir(默認設置)時,以下兩個程序都可以正常工作,但是這會創建相當大的程序。我想用--onefile選項,但是當我運行創建onefile應用程序,我得到的錯誤:PyInstaller錯誤與PyQt時試圖建立--onefile

import sys 
from PyQt4 import QtCore, QtGui 

app =QtGui.QApplication(sys.argv) 
window =QtGui.QMainWindow() 
window.setCentralWidget(QtGui.QLabel("Hello")) 
window.show() 
sys.exit(app.exec_()) 

這:

Traceback (most recent call last): 
    File "<string>", line 11, in <module> 
    File "pyinstaller/PyInstaller/loader/iu.py", line 468, in importHook 
raise ImportError("No module named %s" % fqname) 
ImportError: No module named PyQt4.QtCore 

這兩者出現此錯誤

import sys 
import PyQt4.QtCore, PyQt4.QtGui 

app = PyQt4.QtGui.QApplication(sys.argv) 
window = PyQt4.QtGui.QMainWindow() 
window.setCentralWidget(PyQt4.QtGui.QLabel("Hello")) 
window.show() 
sys.exit(app.exec_()) 

有沒有人有任何想法?

回答

2

1,Pyinstaller不會創建--onefile甚至小於--onedir。當你運行--onefile時,它只是創建一個包裝器,將dir中的所有內容提取到一個臨時目錄,然後運行它。

2,Pyinstaller不支持import PyQt4.QtCore, PyQt4.QtGui,from PyQt4 import QtCore, QtGui是根據here唯一支持的方式。

3,你的PyQt4的版本是? Riverbank的安裝程序是GPL版本嗎?

4,您是否正確地按照步驟操作?例如Makespec.py然後Build.py

PyInstaller -y -F --distpath="." -p "C:\Python27\Lib\site-packages\PyQt4" test.py 

如果從executible安裝PyQt的它所有:

+0

我試圖找到我的例子中的.spec文件爲PyQt的構建我沒有在Linux中而回。我無法找到它,但我認爲我必須對spec文件中的Analysis()定義做些什麼。也許我錯了,我所做的只是'從PyQt4導入QtCore,QtGui'導入語法。 – jdi

+0

事實上,你可以隨時在spec文件中加入'PyQt4',這將確保pyinstaller將它包含進去。 –

+0

您介意如何將PyQt4(或任何其他大型軟件包)添加到spec文件中,讓我介紹一下嗎?恐怕這些文檔不夠清晰,無法理解我在做什麼。 – taynaron

5

工作正常,我(的Windows 7x64bit,巨蟒2.7x32bit)只需添加QT目錄或者您的系統路徑或添加它p選項命令行這個自動爲您:

http://sourceforge.net/projects/pyqt/files/

+0

莫名其妙地pyinstaller沒有自動包含PySide庫。儘管你的解決方案適用於我。但是有沒有其他的解決方法? – dnth