Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 922
taynaron Avatar asked Dec 18 '11 00:12

taynaron


2 Answers

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:\Python27\Lib\site-packages\PyQt4" test.py

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

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

like image 190
mAsT3RpEE Avatar answered Sep 28 '22 20:09

mAsT3RpEE


1, Pyinstaller won't create --onefile even smaller than --onedir. When you run the --onefile, it just creates a wrapper that extract everything in the dir to a temporary directory and then run it.

2, Pyinstaller does not support import PyQt4.QtCore, PyQt4.QtGui, and from PyQt4 import QtCore, QtGui is the only supported way according to here.

3, What's your PyQt4's version? Is is the GPL version from Riverbank's installer?

4, Did you follow the steps correctly? e.g. Makespec.py then Build.py?

like image 25
Felix Yan Avatar answered Sep 28 '22 18:09

Felix Yan