import sys
import os
from Qt import (QtWidgets, __binding__, __binding_version__, __qt_version__, __version__)
def window():
app = QtWidgets.QApplication(sys.argv)
w = QtWidgets.QWidget()
b = QtWidgets.QLabel(w)
b.setText("Hello World!")
w.setGeometry(100, 100, 200, 200)
b.move(50, 20)
w.setWindowTitle("PyQt")
w.show()
sys.exit(app.exec_())
if __name__ == '__main__':
print("__binding__:" + __binding__)
print("__binding_version__:" + __binding_version__)
print("__qt_version__:" + __qt_version__)
print("__version__:" + __version__)
window()
When run from the terminal, this works great, and I see the little Hello World MainWindow.
My HelloQt.spec file is as follows:
# -*- mode: python ; coding: utf-8 -*-
block_cipher = None
a = Analysis(['helloQt.py', 'helloQT.spec'],
pathex=[],
binaries=[],
datas=[],
hiddenimports=['Qt.py'],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
[],
exclude_binaries=True,
name='helloQt',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=False,
disable_windowed_traceback=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None )
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
upx_exclude=[],
name='helloQt')
I run with the following:
pyinstaller -F helloQt.py helloQT.spec --windowed
But I get the following error in the GUI:
Traceback (most recent call last):
File "helloQt.py", line 6, in <module>
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
File "Qt.py", line 1928, in <module>
File "Qt.py", line 1906, in _install
AttributeError: module 'Qt' has no attribute 'QtGui'
Does anybody have some feedback on the AttributeError in the compiled executable, and then feedback on the process to make a single executable with the user-replaceable PySide2 library?
Much appreciated!
Jim