我用 "pip install pywinauto" 成功安装了 package:pywinauto,但总是失败,为什么?

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

所有,

我用"pip install pywinauto"成功安装了package:pywinauto,但总是失败,为什么? 我是这样做的:

pip 安装 pywinauto

然后在 windows cmd 环境下,我 运行 python: 接着: 导入pywinauto 我收到以下错误: ....

>>> 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

我需要将Winxp升级到Win7或Win8,或Win10

看来您使用的是 OS Windows 旧版本,例如 Windows XP。 MS UI 自动化包含在 Windows Vista 及更高版本中。但是您可以安装 .NET Framework 3.0+ 以获得 UIAutomationCore.dll 即使在 Windows XP 上也可用。如果您根本不需要 MS UI 自动化技术,只需 运行 pip uninstall comtypes 和 pywinauto 将仅适用于 Win32 API。

如果安装 .NET Framework 3.0+ 没有帮助(或者如果它已经安装)并且您需要使用 Win XP,请安装 Windows 更新 KB971513。它为我解决了加载库问题。