无法在 Windows 10 上导入 pywinauto

Cannot import pywinauto on Windows 10

我使用 pip install pywinauto 安装了 pywinauto

OS: Windows 10

Python: 3.6.2

当我 运行 python 并尝试导入 pywinauto 时,出现错误:

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'

有什么解决办法吗?

尝试使用不同版本的 python(例如 3.7.5 或 3.8):

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

“与 Python 3.7.6 和 3.8.1 有同样的问题。问题不会出现在 3.7.5 或 3.8 中。 我认为这将在 3.8.2 中修复(但还不确定)"

它应该在 comtypes==1.1.9 中修复。请检查。

问题是在 comtypes==1.1.8 中引入的。我的错。

我今天遇到了同样的问题并已由 pip install comtypes==1.1.7 修复。 它是由 comtypes 库引起的,该库在 12 月 26 日发布了新版本 1.1.8。降级到以前的版本,现在可以正常使用了。

试试这个,对我来说效果很好

  1. https://github.com/mhammond/pywin32/releases
  2. 安装 pywin32
  3. pip install -U comtypes
  4. pip install six
  5. pip install Pillow
  6. cd c:\windows\syswow64\
  7. regsvr32 UIAutomationCore.dll
  8. python
  9. import pywinauto #问题应该解决了

我有 Win10 和 python3.9.....我不喜欢 Win10 另一件事可能是您的 numpy 库,将其卸载并重新安装。 pip 卸载 numpy pip 安装 numpy

致谢名单 -> https://www.dll-files.com/download/65996a0afad353ec43ffe1ca69a2be88/uiautomationcore.dll.html?c=TTM2MGJJaHVRaEJkM1JyNDB3TDNwZz09