PySide2/Qt.py shim - build error/options

60 views
Skip to first unread message

Jim S

unread,
Feb 26, 2022, 11:07:29 AM2/26/22
to PyInstaller
Howdy forum,

I've built an app with PySide2, Python 3.7.9, and the Qt.py shim, that I'd like to now package into an executable.  

To satisfy the PySide2 LGPL terms, I need to package my app in a way that allows the user to substitute the included PySide2 library with their own.  I would prefer to be able to package all of the other components into an executable, and then have a subfolder containing the PySide2-related files.

Could anyone describe a quick approach to do this?  In the process of trying this out, I created this minimum example:

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
Reply all
Reply to author
Forward
0 new messages