Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
423 views
in Technique[技术] by (71.8m points)

python - PyInstaller error with PyQt when trying to build --onefile

I'm trying to compile a PyQt program using PyInstaller 1.5. Both of the following programs work fine for me when I use --onedir (the default), but this creates rather large programs. I want to use the --onefile option, but when I run the created onefile app, I get the error:

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

This error occurs for both this:

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_()) 

and this:

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_()) 

Does anyone have any ideas?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Works Fine for me (Windows 7x64bit, Python 2.7x32bit) simply add QT directory to either your system path or add it to commandline with p option:

PyInstaller -y -F --distpath="." -p "C:Python27Libsite-packagesPyQt4" test.py

If you install PyQt from executible it does all this automatically for you:

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...