3

Currently I am developping a standalone python app and I am now working on the packaging with PyInstaller.

Configuration :

  • OS : Windows 10
  • QGIS : 3.4.9
  • PyInstaller : 3.5

Pyinstaller correctly finds many dependencies and manages to create an executable.

But when I run it, the output is :

  File "C:\PROGRA~1\QGIS3~1.4\apps\Python37\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
    exec(bytecode, module.__dict__)
  File "qgis\gui\__init__.py", line 27, in <module>
RuntimeError: qgis._gui cannot import type '����' from PyQt5.QtCore
[6752] Failed to execute script main

I found that the sip folder in QGIS 3.4\apps\Python37\ contains many files that might be useful, so I manually added the content of sip\PyQt5 in the PyInstaller package with other PyQt5 stuff and the new output is :

  File "C:\PROGRA~1\QGIS3~1.4\apps\Python37\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
    exec(bytecode, module.__dict__)
  File "qgis\gui\__init__.py", line 27, in <module>
RuntimeError: the PyQt5.Qsci module failed to register with the sip module
[4092] Failed to execute script main

Any idea about a file or folder I forgot to package ? For PyInstaller I use a default .spec file.

Reviewing Working Windows Standalone .EXE From QGIS Python Script Using PyInstaller? with QGIS 2 didn't help

1 Answer 1

1

Found a workaround:

I installed QGIS 3.4 LTR and pyinstaller in a miniconda environment on Windows 10.

(Add conda-forge channel to install QGIS)

I had to add the platforms/ directory in the data section of pyinstaller .spec file (qt platform directory found in the conda environment Library/ folder) for Qt to work.

2
  • Any chance you could please share your working spec file please? I am still having this problem even with miniconda.
    – Ben
    Commented Jan 4, 2021 at 18:07
  • Alas, I can't reproduce the working environment...! I was probably lucky with a specific version of pyinstaller or QGIS or both... As for now I ask my users to have QGIS preinstalled as a requirement, and I package my standalone python scripts in their APPDATA folder on Windows.
    – Djedouas
    Commented Jan 6, 2021 at 9:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.