0

I tried to create a test executable using the command pyinstaller -F helloQT.py that uses QT and I get the following error:

$ ./helloQT.exe
Traceback (most recent call last):
  File "helloQT.py", line 2, in <module>
ModuleNotFoundError: No module named 'Qt'
[12884] Failed to execute script helloQT

Here is my source file:

import sys
from Qt.QtWidgets import QApplication, QWidget, QLabel

def window():
    app = QApplication(sys.argv)
    w = QWidget()
    b = QLabel(w)
    b.setText("Hello World!")
    w.setGeometry(100, 100, 200, 50)
    b.move(50, 20)
    w.setWindowTitle("PyQt")
    w.show()
    sys.exit(app.exec_())


if __name__ == '__main__':
    window()

So I am using python 3.8.2 with packages:

Package        Version
-------------- ---------
pip            20.0.2
PyInstaller    3.6
PySide2        5.14.2
Qt.py          1.2.5

(I have a few other packages but I think these are the relevant ones)

Running it the standard way python helloQT.py results in expected execution:

enter image description here

What do I need to do differently to allow this to execute correctly? Ultimately I am trying to get a larger exsisiting program build on QTpy abstraction to PySide2 to run in this way but I was having issues. My hope is to better understand this toy problem before attacking my larger project.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Jim
  • 2,034
  • 2
  • 15
  • 29

1 Answers1

1

Probably, PyInstaller doesn't know about Qt.py. While PySide2 is listed as supported, Qt.py is not.

So you will probably have to tell PyInstaller to include Qt.py. See e.g. here.

Roland Smith
  • 42,427
  • 3
  • 64
  • 94
  • Qt.py is different to qtpy – eyllanesc Apr 02 '20 at 03:18
  • So I followed the guidance from that page and ran the command `pyinstaller -F helloQT.py --hidden-import=Qt.py --debug=imports` which didnt seem to change anything so then I ran the command `pyinstaller -F helloQT.py --hidden-import=Qt --debug=imports` which then gives me an error like 'AttributeError: partially initialized module 'Qt' has no attribute 'QtGui' (most likely due to a circular import)` I am not really sure how to use the out put of the --debug=imports output to determine what to put in the --hidden-import section – Jim Apr 02 '20 at 13:18
  • Looking more closely at the output of the pyinstaller I see the line `7119 ERROR: Hidden import 'Qt.py' not found` (but only when I use Qt.py no such error with Qt – Jim Apr 02 '20 at 13:32
  • @eyllanesc what is the difference between qtpy and Qt.py it seems the attempt to solve the same problem? Does pyinstaller work with qtpy? – Jim Apr 02 '20 at 15:13
  • @Jim It is that there are 2 libraries that implement 2 different ways to create a PyQt5 and PySide2 wrapper. – eyllanesc Apr 02 '20 at 15:22