【问题标题】:Cannot import pywinauto on Windows 10无法在 Windows 10 上导入 pywinauto
【发布时间】:2020-12-26 18:50:07
【问题描述】:

我使用pip install pywinauto 安装了pywinauto

操作系统: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'

任何想法如何解决这个问题?

【问题讨论】:

  • 我不知道它是否有任何帮助,但可能值得尝试从互联网上下载 UIAutomationCore.dll

标签: python python-3.x pywinauto


【解决方案1】:

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

【讨论】:

  • 现在已修复在comtypes==1.1.9。请检查。
【解决方案2】:

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

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

【讨论】:

  • 是的,Windows PATH 是一团糟。但是,import pywinauto 从不工作变为工作,而我没有接触到 PATH 变量。我所做的其中一个安装修改了我的PATH 以使其正常工作,或者发生了其他事情。
  • 问题出在comtypes。我在comtypes==1.1.9 中修复了它。请检查。
  • 在 comtypes==1.1.9 中也遇到同样的问题...撤回到 1.1.7 并且效果很好
  • 同样的问题在 1.1.12 中仍然存在,降级到 1.1.9 对我有用。感谢@VasilyRyabov 的提醒
  • @VasilyRyabov 是的 comtypes==1.1.11 也可以,摆脱这个错误。
【解决方案3】:

尝试使用不同版本的 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 中修复(但还不确定)”

【讨论】:

  • 所以我安装了各种 Python 版本,在每种情况下我都安装了python3.x -m pip install pywinauto。在每种情况下,安装都成功完成。每次安装后,我都启动了对应的 Python 并尝试了import pywinauto。我安装的版本是 3.7.3、3.7.9、3.8.7 和 3.9.1(除了原来的 3.6.2)。在每种情况下,我都收到了我原始帖子中描述的错误。所以我决定发表这条评论,并开始在每个 python 版本中再次运行import pywinauto。令我完全惊讶的是,原来的 3.6.2 现在可以工作了!!! Windows之谜!!!
  • 也许是新版本的comtypes。试试 comtypes==1.1.7。
  • comtypes==1.1.10 对 Win7 和 Win10 都有更合适的修复,仅供参考。
【解决方案4】:

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

  1. https://github.com/mhammond/pywin32/releases安装pywin32
  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 #问题应该解决了

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

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

【讨论】:

  • 在 Windows 7 上安装 Pillow 似乎对我有用。
  • 它应该在comtypes==1.1.9中修复,没有任何其他技巧。请检查。
猜你喜欢
  • 2017-09-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-11-11
  • 2019-04-27
  • 2018-12-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多