Cannot import pywinauto on Windows 10

Tags: , ,

I installed pywinauto using pip install pywinauto.

OS: Windows 10

Python: 3.6.2

When I run python and try to import pywinauto, I get the error:

Python 3.6.2 (v3.6.2:5fd33b5, Jul  8 2017, 04:57:36) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from pywinauto.application import Application
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "", line 89, in <module>
    from . import findwindows
  File "", line 42, in <module>
    from . import controls
  File "", line 36, in <module>
    from . import uiawrapper # register "uia" back-end (at the end of uiawrapper module)
  File "", line 47, in <module>
    from ..uia_defines import IUIA
  File "", line 181, in <module>
    pattern_ids = _build_pattern_ids_dic()
  File "", line 169, in _build_pattern_ids_dic
    if hasattr(IUIA().ui_automation_client, cls_name):
  File "", line 50, in __call__
    cls._instances[cls] = super(_Singleton, cls).__call__(*args, **kwargs)
  File "", line 60, in __init__
    self.UIA_dll = comtypes.client.GetModule('UIAutomationCore.dll')
  File "", line 118, in GetModule
    mod = _CreateWrapper(tlib, pathname)
  File "", line 183, in _CreateWrapper
    generate_module(tlib, ofi, pathname)
  File "", line 750, in generate_module
    gen.generate_code(list(items.values()), filename=pathname)
  File "", line 261, in generate_code
    tlib_mtime = os.stat(self.filename).st_mtime
FileNotFoundError: [WinError 2] The system cannot find the file specified: 'UIAutomationCore.dll'

Any ideas how to fix this?


I have the same issue today and fixed it by pip install comtypes==1.1.7. It caused by comtypes library which release a new version 1.1.8 at Dec.26. Downgrade to previous version, it works well now.

Source: stackoverflow