Search code examples
pythonwindowspywinauto

I've installed the package:pywinauto successfully with "pip install pywinauto", but it always fail, why?


all,

I've installed the package:pywinauto successfully with "pip install pywinauto", but it always fails, why? I did it in this way:

pip install pywinauto

and then under the windows cmd env, I run the python: and then: import pywinauto I got the following errors: ....

>>> import pywinauto
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\pywinauto\__init__.py", line 40, in <module>
    from . import findwindows
  File "C:\Python27\lib\site-packages\pywinauto\findwindows.py", line 42, in <module>
    from . import controls
  File "C:\Python27\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:\Python27\lib\site-packages\pywinauto\controls\uiawrapper.py", line 44, in <module>
    from ..uia_defines import IUIA
  File "C:\Python27\lib\site-packages\pywinauto\uia_defines.py", line 175, in <module>
    pattern_ids = _build_pattern_ids_dic()
  File "C:\Python27\lib\site-packages\pywinauto\uia_defines.py", line 163, in _build_pattern_ids_dic
    if hasattr(IUIA().ui_automation_client, cls_name):
  File "C:\Python27\lib\site-packages\pywinauto\uia_defines.py", line 50, in __call__
    cls._instances[cls] = super(_Singleton, cls).__call__(*args, **kwargs)
  File "C:\Python27\lib\site-packages\pywinauto\uia_defines.py", line 60, in __init__
    self.UIA_dll = comtypes.client.GetModule('UIAutomationCore.dll')
  File "C:\Python27\lib\site-packages\comtypes\client\_generate.py", line 97, in GetModule
    tlib = comtypes.typeinfo.LoadTypeLibEx(tlib)
  File "C:\Python27\lib\site-packages\comtypes\typeinfo.py", line 485, in LoadTypeLibEx
    _oleaut32.LoadTypeLibEx(c_wchar_p(szFile), regkind, byref(ptl))
  File "_ctypes/callproc.c", line 950, in GetResult
WindowsError: [Error -2147312566] Error loading type library/DLL

Solution

  • It looks like you're using old OS Windows version like Windows XP. MS UI Automation is included into Windows Vista and later. But you may install .NET Framework 3.0+ to get UIAutomationCore.dll available even on Windows XP. If you don't need MS UI Automation technology at all, just run pip uninstall comtypes and pywinauto will work with Win32 API only.