AttributeError: module 'comtypes.gen.UIAutomationClient' has no attribute 'CUIAutomation
See original GitHub issueExpected Behavior
When running a script with a very single line such as
from pywinauto import Application
or
import pywinauto,
I should not get any error message.
Actual Behavior
I do get error messages:
D:\PycharmProjects\project_a\venv\lib\site-packages\pywinauto\__init__.py:72: UserWarning: Apply externally defined coinit_flags: 0 .format(module_sys.coinit_flags), UserWarning) Traceback (most recent call last): File "<input>", line 1, in <module> File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 2018.1\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 20, in do_import module = self._system_import(name, *args, **kwargs) File "D:\PycharmProjects\project_a\venv\lib\site-packages\pywinauto\__init__.py", line 89, in <module> from . import findwindows File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 2018.1\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 20, in do_import module = self._system_import(name, *args, **kwargs) File "D:\PycharmProjects\project_a\venv\lib\site-packages\pywinauto\findwindows.py", line 42, in <module> from . import controls File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 2018.1\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 20, in do_import module = self._system_import(name, *args, **kwargs) File "D:\PycharmProjects\project_a\venv\lib\site-packages\pywinauto\controls\__init__.py", line 36, in <module> from . import uiawrapper # register "uia" back-end (at the end of uiawrapper module) File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 2018.1\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 20, in do_import module = self._system_import(name, *args, **kwargs) File "D:\PycharmProjects\project_a\venv\lib\site-packages\pywinauto\controls\uiawrapper.py", line 47, in <module> from ..uia_defines import IUIA File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 2018.1\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 20, in do_import module = self._system_import(name, *args, **kwargs) File "D:\PycharmProjects\project_a\venv\lib\site-packages\pywinauto\uia_defines.py", line 181, in <module> pattern_ids = _build_pattern_ids_dic() File "D:\PycharmProjects\project_a\venv\lib\site-packages\pywinauto\uia_defines.py", line 169, in _build_pattern_ids_dic if hasattr(IUIA().ui_automation_client, cls_name): File "D:\PycharmProjects\project_a\venv\lib\site-packages\pywinauto\uia_defines.py", line 50, in __call__ cls._instances[cls] = super(_Singleton, cls).__call__(*args, **kwargs) File "D:\PycharmProjects\project_a\venv\lib\site-packages\pywinauto\uia_defines.py", line 63, in __init__ self.ui_automation_client.CUIAutomation().IPersist_GetClassID(), **AttributeError: module 'comtypes.gen.UIAutomationClient' has no attribute 'CUIAutomation**'
I found kind of similar issue described there: https://github.com/pywinauto/pywinauto/issues/513
But reinstalling comtypes==1.1.5 didnt change anything. Currently, I do have comtypes==1.1.7 installed. To be accurate, when I forced the installation of comtypes==1.1.5, it failed, and rolled back to 1.1.7.
pywinauto was installed without any issue.
In my venv there is also: pywin32==228 pywinauto==0.6.8 win32core==221.36 win32gui==221.6
Steps to Reproduce the Problem
Short Example of Code to Demonstrate the Problem
pip install pywinauto, #no issue from pywinauto import Application # it fails import pywinauto # it fails as well.
Specifications
- Pywinauto version: 0.6.8
- Python version and bitness: Python 3.6
- Platform and OS: Windows 7
I’m clueless regarding the cause of this issue.
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (1 by maintainers)

Top Related StackOverflow Question
I was having the same problem when using Python 3.8.5, just changed the python version to 3.8.3, that solved the problem for me!, Try this out and let me know
Прощу прощения - просмотрел команду по очистке кэша https://github.com/pywinauto/pywinauto/issues/513#issuecomment-411556088 .
В моем случае команда выглядела следующим образом (Powershell от Администратора):
После выполнения команды - проблема перестала возникать. Перезагрузка ОС не требуется, достаточно перезапустить Python.