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?

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?

I'm "compiling" a program using PyInstaller using a .spec file. I'm using the .spec file because I need to include an extra file in the program. When I try to do PyInstaller --onefile Prog.spec, it still makes a folder in dist with all the files separate instead of making a

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/

Thanks Leandro! I spent AGES trying to get my icon working Pyinstaller is new to me, and I think I would have been here all night if you hadn't written this explanation. All the best. – Kim Nov 8 '12 at 21:23

I had the same problem with pyinstaller 3.4 (python 3.6, PyQt5) and finally got it working by adapting the solutions found in here and here.

The method summarized:

1) Run "pip install pip==18.1". It was crucial to use version 18.1 although newer ones also exist. After the process you can upgrade pip by "pip install pip --upgrade"

2) Install pyinstaller development version: "pip install https://github.com/pyinstaller/pyinstaller/archive/develop.tar.gz"

3 ) Run pyinstaller normally

Hope this helps!

Hi all! Translate a script in Python to EXE using pyinstaller. Came out this error,trying to byte 0xed in position 87: invalid continuation byte

And finally, run PyInstaller with your new spec file. For example, when I’m generating a bundle for Quaver, I do pyinstaller quaver-onefile.spec. 2.2.2 Generating a bundle for macOS. PyInstaller is really good for creating bundles that conform to Apple’s Bundle Structure, making them easily code-signable.

Traceback (most recent call last): File "site-packages\PyInstaller\loader\rthooks\pyi_rth_qt5plugins.py", line 46, in <module> File "C:\Program Files\Python35\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 573, in load_module module = loader.load_module(fullname) ImportError: DLL load failed: The specified module could not be

Then, I try to build an .exe: D:\pyinstaller>python Makespec.py --onefile --upx D:\test\test.py wrote D:\pyinstaller\test\test.spec now run Build.py to build the executable D:\pyinstaller>python Build.py test\test.spec I: Dependent assemblies of C:\Python27\python.exe: I: x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.21022.8_none checking

Comments
  • I was trying to find my example .spec file for a PyQt build I did a while back on a linux box. I couldnt find it, but I thought I had to do something with the Analysis() definition in the spec file. Maybe Im wrong and all I did was the from PyQt4 import QtCore, QtGui import syntax.
  • In fact, you can always add PyQt4 to the spec file which will ensure that pyinstaller will include it.
  • Would you mind walking me through how to add PyQt4 (or any other large package) to the spec file? I'm afraid the docs aren't sufficiently clear for me to understand what I'm doing.
  • I'm running the latest trunk version of PyInstaller, and I am running the latest MacPorts version of PyQt. I am running Build.py with a previously generated .spec file.
  • I finally just went with --onedir, since as @FelixYan mentioned, it doesn't save any HDD space in the long run (and slows things down a bit since you have to extract the program's contents each time). Thanks!
  • somehow pyinstaller did not include the PySide library automatically. Your solution works for me though. But is there any other workaround?