Home > Enterprise >  PyInstaller main.exe can't import PySide2.QtQuick
PyInstaller main.exe can't import PySide2.QtQuick

Time:07-17

I packaged my Qt/QML application that uses Pyside2 using pyinstaller and I run into the following error:

C:\WorkDir\Development\Source\App\dist\main>main
Traceback (most recent call last):
  File "main.py", line 9, in <module>
  File "C:\Users\USER\AppData\Local\Temp\embedded.4bpi2020.zip\shibokensupport\__feature__.py", line 142, in _import
ImportError: could not import module 'PySide2.QtQuick'
[28752] Failed to execute script 'main' due to unhandled exception!

In the IDE it works fine, but after I build it with PyInstaller, it throws the error above. I use Poetry as my package manger, so maybe this is the issue and PyInstaller doesn't see or doesn't copy the needed files to the dist folder.

That being said, I see a folder name PySide2 in the dist folder, along with many Qt5 dlls:

enter image description here

Does anyone know why this might happen or have a hit as to how this issue might be resolved?

CodePudding user response:

A user over at Qt Forum pointed me to an answer:

You can try the hidden import option. --hidden-import=PySide2.QtQuick for CLI or hiddenimports=['PySide2.QtQuick'] in the spec file.

And this solved the issue.

  • Related