安装pywinauto后,我尝试运行该简单代码:
from pywinauto import Application
filename = 'notepad.exe'
app = aplication.Application().start(filename)
并得到错误:
Traceback (most recent call last):
File "D:\auto\retr\test.py", line 1, in <module>
from pywinauto import Application
File "D:\Users\222\AppData\Local\Programs\Python\Python39\lib\site-packages\pywinauto\__init__.py", line 89, in <module>
from . import findwindows
File "D:\Users\222\AppData\Local\Programs\Python\Python39\lib\site-packages\pywinauto\findwindows.py", line 42, in <module>
from . import controls
File "D:\Users\222\AppData\Local\Programs\Python\Python39\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 "D:\Users\222\AppData\Local\Programs\Python\Python39\lib\site-packages\pywinauto\controls\uiawrapper.py", line 42, in <module>
from .. import backend
File "D:\Users\222\AppData\Local\Programs\Python\Python39\lib\site-packages\pywinauto\backend.py", line 35, in <module>
from .base_wrapper import BaseWrapper
File "D:\Users\222\AppData\Local\Programs\Python\Python39\lib\site-packages\pywinauto\base_wrapper.py", line 44, in <module>
import win32ui
ImportError: DLL load failed while importing win32ui: A dynamic link library (DLL) initialization routine failed.
如果我确实明确导入了win32ui:
import win32ui
from pywinauto import Application
错误变得更简单,但与以下内容无关:
Traceback (most recent call last):
File "D:\auto\retr\test.py", line 1, in <module>
import win32ui
ImportError: DLL load failed while importing win32ui: A dynamic link library (DLL) initialization routine failed.
我用Google搜索了类似的问题,但没有找到任何解决方案。
我有Win10,python 3.9
答案 0 :(得分:2)
这似乎是Trying to use win32ui with pywin32 gives: A dynamic link library (DLL) initialization routine failed的副本
从那和the Github page的外观来看,import win32ui
实际上是使用pywin32 build 228在Python 3.9上损坏的。在另一个问题中发布了一种解决方法。简短的故事是首选229版本,在该版本发布之前,Github页上有一种解决方法,可以手动安装已打补丁的228版本的派生版本或229版本的手动版本。
为方便起见,可以在here中找到 .whls 。下载适当的文件并使用:
pip install -U --force-reinstall <FILE>.whl
问题很可能会得到解决。