问题描述
在 Windows 8 上运行 python 3.6.
Running python 3.6 on windows 8.
ModuleNotFoundError: No module named 'win32gui'
我已经尝试过多次安装 pywin32,但到目前为止都没有奏效.https://sourceforge.net/projects/pywin32/files/pywin32/Build%20221/ 通过安装没有问题,但问题说服了.与 pip 安装相同:http://www.lfd.uci.edu/~gohlke/pythonlibs/#pywin32
I have tried multiple installations of pywin32 but none have worked so far.https://sourceforge.net/projects/pywin32/files/pywin32/Build%20221/ goes through installation without problems but the issue persuades.Same with pip installing: http://www.lfd.uci.edu/~gohlke/pythonlibs/#pywin32
在我的 Python 根目录中,site-packages 文件夹中现在有多个 pywin32/win32 变体.pywin32.pth 不包含 win32gui,仅包含以下内容:
In my Python root there is now multiple pywin32/win32 variants in the site-packages folder. pywin32.pth doesn't contain a win32gui but only the following:
# PyWin32 扩展的 .pth 文件赢32win32lib蟒蛇
我可以作为最后的手段切换到另一个 GUI 工具包,但由于我使用了一些开源代码,这意味着我必须重写大量代码,这就是为什么它是最后的手段.
I could as a last resort switch to another GUI toolkit but as I'm using some opensource code that would mean I'd have to rewrite lots of code which is why it is a last resort.
更新:更改导入行:
import win32gui, win32ui, win32con, win32api
致:
from win32 import win32gui, win32ui, win32con, win32api
将错误推送到:
ImportError: cannot import name 'win32ui'
解决方案更新:
from win32 import win32gui
import win32ui, win32con, win32api
推荐答案
这看起来很像 32 位/64 位问题.如果您正在运行 64 位 Python 并且拥有 32 位 PythonWin,您将看到这种情况.win32gui
和 win32ui
都是 .pyd
文件(DLL),它们应该位于 Libsite-packageswin32
和 Libsite-packagespythonwin
分别.
This looks very much like a 32-bit/64-bit issue. If you are running 64-bit Python and you have 32-bit PythonWin you will see this sort of thing. Both win32gui
and win32ui
are .pyd
files (DLLs) and they should live in Libsite-packageswin32
and Libsite-packagespythonwin
respectively.
如果您可以在那里看到它们但导入失败,那么它们很可能是错误的位.64 位可执行文件无法加载 32 位 DLL,反之亦然,如果您尝试,在大多数情况下,错误消息会告诉您您尝试加载的 DLL 不存在.即使你可以看到它是.
If you can see them there but the import is failing then it is likely they are the wrong bitness. A 64-bit executable cannot load a 32-bit DLL and vice versa, and if you try, in most cases the error message will tell you that the DLL you are trying to load isn't there. Even when you can see that it is.
编辑以下与 OP 的评论交流:
如果在一行中放置多个导入,PythonWin 也会出现此类错误.按照 PEP-8 对一行进行一次导入.
You will also get this sort of error with PythonWin if you put multiple imports in a single line. Follow PEP-8 and do one import to a line.
这篇关于安装pywin32后Python“没有名为win32gui的模块"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!