Getting error while running a script which uses pywinauto

Viewed 1402

Whenever I import pywinauto I am getting below error " Traceback (most recent call last): File "D:\Python\Python38\lib\ctypes_init_.py", line 123, in WINFUNCTYPE return _win_functype_cache[(restype, argtypes, flags)] KeyError: (, (, , ), 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:/Users/tejaw/PycharmProjects/xxxxxxxx/Sample.py", line 3, in import pywinauto File "D:\Python\Python38\lib\site-packages\pywinauto_init_.py", line 89, in from . import findwindows File "D:\Python\Python38\lib\site-packages\pywinauto\findwindows.py", line 42, in from . import controls File "D:\Python\Python38\lib\site-packages\pywinauto\controls_init_.py", line 36, in from . import uiawrapper # register "uia" back-end (at the end of uiawrapper module) File "D:\Python\Python38\lib\site-packages\pywinauto\controls\uiawrapper.py", line 47, in from ..uia_defines import IUIA File "D:\Python\Python38\lib\site-packages\pywinauto\uia_defines.py", line 181, in pattern_ids = _build_pattern_ids_dic() File "D:\Python\Python38\lib\site-packages\pywinauto\uia_defines.py", line 169, in _build_pattern_ids_dic if hasattr(IUIA().ui_automation_client, cls_name): File "D:\Python\Python38\lib\site-packages\pywinauto\uia_defines.py", line 50, in call cls._instances[cls] = super(_Singleton, cls).call(*args, **kwargs) File "D:\Python\Python38\lib\site-packages\pywinauto\uia_defines.py", line 60, in init self.UIA_dll = comtypes.client.GetModule('UIAutomationCore.dll') File "D:\Python\Python38\lib\site-packages\comtypes\client_generate.py", line 110, in GetModule mod = _CreateWrapper(tlib, pathname) File "D:\Python\Python38\lib\site-packages\comtypes\client_generate.py", line 184, in _CreateWrapper mod = _my_import(fullname) File "D:\Python\Python38\lib\site-packages\comtypes\client_generate.py", line 24, in my_import return import(fullname, globals(), locals(), ['DUMMY']) File "D:\Python\Python38\lib\site-packages\comtypes\gen_944DE083_8FB8_45CF_BCB7_C477ACB2F897_0_1_0.py", line 1931, in IUIAutomation.methods = [ File "D:\Python\Python38\lib\site-packages\comtypes_init.py", line 329, in setattr self.make_methods(value) File "D:\Python\Python38\lib\site-packages\comtypes_init.py", line 698, in make_methods prototype = WINFUNCTYPE(restype, *argtypes) File "D:\Python\Python38\lib\ctypes_init.py", line 125, in WINFUNCTYPE class WinFunctionType(_CFuncPtr): TypeError: item 2 in argtypes passes a union by value, which is unsupported. "

Please do help me in this.

1 Answers

This is Python bug in Python 2.7.6 and 3.8.1. Please do clean install of Python 3.7.7+ or 3.8.2+.

Full history of the issue is here: https://github.com/pywinauto/pywinauto/issues/868

This is a missing feature in libffi for passing union by value. libffi is used by ctypes for resolving calling convention at runtime. Python Core developers decided to prohibit this option due to missing feature. But it was wrong decision that broke a lot of users on Windows. So the wrong patch was reverted in Python 3.7.7 / 3.8.2.

Related