问题描述
在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:
# .pth file for the PyWin32 extensionswin32win32\libPythonwin
# .pth file for the PyWin32 extensionswin32win32\libPythonwin
作为最后的选择,我可以切换到另一个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.
更新:将导入行从以下位置更改:
Update:changing the import line from:
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),它们应该分别位于Lib\site-packages\win32
和Lib\site-packages\pythonwin
中.
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 Lib\site-packages\win32
and Lib\site-packages\pythonwin
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'No module named win32gui'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!