Include Qt.py to application with Pyinstaller
paulwinex opened this issue · 5 comments
I try to build application with Pyinstaller 3.6.
If i add Qt and PySIde2 to the hidden imports i catch error:
ModuleNotFoundError: No module named 'Qt'
When i exclude Qt for using external original module Qt.py i catch this error:
ModuleNotFoundError: No module named 'Qt.QtWidgets'; 'Qt' is not a package
Can you help me how i can correct include Qt.py to the build?
I use spec file
from PyInstaller.utils.hooks import collect_submodules
import PySide2, sys
import ntpath
from pathlib import Path
root = Path(os.getcwd()).parent
icon = root.parent / 'ui' / 'icons' / 'app.ico'
name = 'myapp'
hidden = collect_submodules('pkg_resources') + collect_submodules('PIL')
a = Analysis([Path('../ui/__main__.py').absolute().as_posix()],
pathex=[os.path.join(ntpath.dirname(PySide2.__file__), 'Qt', 'bin')],
binaries=[
('/lib/x86_64-linux-gnu/libc.so.6', '.')
],
datas=[],
hiddenimports=hidden+['PySide2', 'Qt'],
hookspath=None,
runtime_hooks=None,
excludes=None,
win_no_prefer_redirects=None,
win_private_assemblies=None,
cipher=None)
pyz = PYZ(a.pure, a.zipped_data,
cipher=None)
exe = EXE(pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
a.binaries,
name=name,
debug=False,
strip=None,
upx=True,
console=True,
icon=icon
)
Python 3.7
Pyinstaller 3.6
Debian 10
https://gist.github.com/paulwinex/0fd7b25a9c646fba05e3ccc4c2ca6d51
This is simple example project with same problem.
Hm, that's funny. I used both Qt.py and PySide2 with fbs (fbs uses pyinstaller) and that worked fine.
I did not use pyinstaller hooks but instead I just made a dummy module which performed a bunch of imports. For PySide2 I had to do the following;
from PySide2 import QtXml from PySide2 import QtUiTools
But I didn't have to do anything in particular to make Qt.py work.
I using import from Qt only. Not "from PySide2...", only "from Qt import...".
And this import is broke compiled app.
Try to make work this!
This isn't really a supported usecase for Qt.py since you no longer have a need to support more than the binding you bundle?
The simple solution would be to bundle PySide2 and make Qt.py look like it.
sys.modules["Qt"] = PySide2
Now whenever Qt.py is imported it would instead get PySide2. But again this is outside the scope of Qt.py.
Actually my app no need to compile. It is temporary solution for solve specific problem.
I add this code in startup script:
import PySide
from PySide2 import QtWidgets, QtCore, QtGui
sys.modules['Qt'] = PySide2
sys.modules['Qt.QtWidgets'] = QtWidgets
sys.modules['Qt.QtCore'] = QtCore
sys.modules['Qt.QtGui'] = QtGui
And compiled version is works!
I think i need map more names but it will be clear in the process.
Thanks