pyinstaller-hooks-contrib
pyinstaller-hooks-contrib copied to clipboard
unable to create executable using pyinstaller for kivy application containing pywinauto
Hi guys, I was creating an executable for kivy application. And it uses a python script that requires pywinauto. After building the exe using pyinistaller on the spec file, I was unable to access the exe. It is throwing an error with thread issue concerning comtypes of pywinauto.
I built this on Ananconda.
I got the following error down below.
Has anyone encountered the same? Please help , need to resolve this soon
- Which hook/library isn't working? Pyinstaller is unable to create exe for python file with pywinauto reference.
- Does the error get raised while building or when running? Error when running the exe
import pywinauto.application File "", line 991, in _find_and_load File "", line 975, in _find_and_load_unlocked File "", line 671, in load_unlocked File "PyInstaller\loader\pyimod03_importers.py", line 476, in exec_module File "pywinauto_init.py", line 87, in File "", line 991, in _find_and_load File "", line 975, in _find_and_load_unlocked File "", line 671, in _load_unlocked File "PyInstaller\loader\pyimod03_importers.py", line 476, in exec_module File "pywinauto\sysinfo.py", line 44, in File "", line 991, in _find_and_load File "", line 975, in find_and_load_unlocked File "", line 671, in load_unlocked File "PyInstaller\loader\pyimod03_importers.py", line 476, in exec_module File "comtypes_init.py", line 160, in File "comtypes_init.py", line 151, in CoInitializeEx File "_ctypes/callproc.c", line 935, in GetResult OSError: [WinError -2147417850] Cannot change thread mode after it is set
I want to run my kivy application as exe A clear and concise description of what you expected to happen.

Desktop (please complete the following information):
- OS: Windows
- Python Version: 3.8.8
- Version of
pyinstaller-hooks-contrib: 2021.3 - Version of PyInstaller - 4.6
This looks like a variant of pyinstaller/pyinstaller#6198, which is caused by win32com being imported before the other package that tries to set the thread mode (which in this case seems to be comtypes).
In PyInstaller-frozen application, win32com is automatically imported via the pkg_resources and win32com runtime hooks, so the work-around is to modify those runtime hooks to import the other package before they import pkg_resources and win32com, as per https://github.com/pyinstaller/pyinstaller/issues/6198#issuecomment-917376441.