John Anderson
John Anderson

Reputation: 38822

Cannot import pywinauto on Windows 10

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 "C:\Users\John\AppData\Roaming\Python\Python36\site-packages\pywinauto\__init__.py", line 89, in <module>
    from . import findwindows
  File "C:\Users\John\AppData\Roaming\Python\Python36\site-packages\pywinauto\findwindows.py", line 42, in <module>
    from . import controls
  File "C:\Users\John\AppData\Roaming\Python\Python36\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:\Users\John\AppData\Roaming\Python\Python36\site-packages\pywinauto\controls\uiawrapper.py", line 47, in <module>
    from ..uia_defines import IUIA
  File "C:\Users\John\AppData\Roaming\Python\Python36\site-packages\pywinauto\uia_defines.py", line 181, in <module>
    pattern_ids = _build_pattern_ids_dic()
  File "C:\Users\John\AppData\Roaming\Python\Python36\site-packages\pywinauto\uia_defines.py", line 169, in _build_pattern_ids_dic
    if hasattr(IUIA().ui_automation_client, cls_name):
  File "C:\Users\John\AppData\Roaming\Python\Python36\site-packages\pywinauto\uia_defines.py", line 50, in __call__
    cls._instances[cls] = super(_Singleton, cls).__call__(*args, **kwargs)
  File "C:\Users\John\AppData\Roaming\Python\Python36\site-packages\pywinauto\uia_defines.py", line 60, in __init__
    self.UIA_dll = comtypes.client.GetModule('UIAutomationCore.dll')
  File "C:\Users\John\AppData\Roaming\Python\Python36\site-packages\comtypes\client\_generate.py", line 118, in GetModule
    mod = _CreateWrapper(tlib, pathname)
  File "C:\Users\John\AppData\Roaming\Python\Python36\site-packages\comtypes\client\_generate.py", line 183, in _CreateWrapper
    generate_module(tlib, ofi, pathname)
  File "C:\Users\John\AppData\Roaming\Python\Python36\site-packages\comtypes\tools\tlbparser.py", line 750, in generate_module
    gen.generate_code(list(items.values()), filename=pathname)
  File "C:\Users\John\AppData\Roaming\Python\Python36\site-packages\comtypes\tools\codegenerator.py", 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?

Upvotes: 12

Views: 8642

Answers (4)

Vasily Ryabov
Vasily Ryabov

Reputation: 9981

It should be fixed in comtypes==1.1.9. Please check.

The problem was introduced in comtypes==1.1.8. My fault.

Upvotes: 4

Jose Morales
Jose Morales

Reputation: 1

Try this, for me works fine

  1. Install pywin32 from https://github.com/mhammond/pywin32/releases
  2. pip install -U comtypes
  3. pip install six
  4. pip install Pillow
  5. cd c:\windows\syswow64\
  6. regsvr32 UIAutomationCore.dll
  7. python
  8. import pywinauto #and the problem should be solved

I have Win10 and python 3.9..... i don't like Win10 Another thing could be your numpy library, uninstall it and install it again. pip uninstall numpy pip install numpy

Credits -> https://www.dll-files.com/download/65996a0afad353ec43ffe1ca69a2be88/uiautomationcore.dll.html?c=TTM2MGJJaHVRaEJkM1JyNDB3TDNwZz09

Upvotes: 0

Michael Wei
Michael Wei

Reputation: 404

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.

Upvotes: 24

Dev Doshi
Dev Doshi

Reputation: 170

Try using a different version of python (e.g. 3.7.5 or 3.8):

https://github.com/pywinauto/pywinauto/issues/887

"Had the same issue with Python 3.7.6 and 3.8.1. Issue does not occur in 3.7.5 or 3.8. I think this will be fixed in 3.8.2 ( but not sure yet)"

Upvotes: 0

Related Questions