question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AttributeError: module 'comtypes.gen.UIAutomationClient' has no attribute 'CUIAutomation

See original GitHub issue

Expected 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:open
  • Created 3 years ago
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
eshraj302commented, Jul 25, 2020

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

0reactions
x1nascommented, May 9, 2022

Есть две виртуалки с pywinauto. Состав и версии python пакетов идентичны.

Python 3.8.10. pywinauto 0.6.8 comtypes 1.1.11 pywin32 304 six 1.16.0

В одном случае возникает ошибка

AttributeError: module 'comtypes.gen.UIAutomationClient' has no attribute 'CUIAutomation'

В другом - такой ошибки не возникает и все работает.

В тикетах никакого решения не нашел.

Прощу прощения - просмотрел команду по очистке кэша https://github.com/pywinauto/pywinauto/issues/513#issuecomment-411556088 .

В моем случае команда выглядела следующим образом (Powershell от Администратора):

& 'C:\Program Files\Python38\python.exe' 'C:\Program Files\Python38\Scripts\clear_comtypes_cache.py' -y

После выполнения команды - проблема перестала возникать. Перезагрузка ОС не требуется, достаточно перезапустить Python.

Read more comments on GitHub >

github_iconTop Results From Across the Web

module 'comtypes.gen.UIAutomationClient' has no attribute ...
Trying to use pywinauto for the very first time and stuck with this issue. Environment - Windows 10 x64 Version 1709 (OS Build...
Read more >
AttributeError: 'module' object has no attribute 'CUIAutomation
AttributeError: module 'comtypes.gen.UIAutomationClient' has no attribute 'CUIAutomation' [15964] Failed to execute script SVGWalker.
Read more >
AttributeError: module 'comtypes.gen.UIAutomationClient' has ...
AttributeError : module 'comtypes.gen.UIAutomationClient' has no attribute 'CUIAutomation.
Read more >
AttributeError: module 'comtypes.gen.UIAutomationClient' has ...
AttributeError : module 'comtypes.gen.UIAutomationClient' has no attribute 'CUIAutomation'问题解决_originaldemo的博客-CSDN博客
Read more >
[TOOL] Gilan's Encounter Counter (Beta Available) v1.0.3 ...
AttributeError : module 'comtypes.gen.UIAutomationClient' has no attribute 'CUIAutomation'. tried a reinstall and no luck on fixing it.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found