python win32gui安装,安装pywin32之后,Python'No module named win32gui'

Running python 3.6 on windows 8.

ModuleNotFoundError: No module named 'win32gui'

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

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 extensions

win32

win32\lib

Pythonwin

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

To:

from win32 import win32gui, win32ui, win32con, win32api

Pushed the error to:

ImportError: cannot import name 'win32ui'

Solution update:

from win32 import win32gui

import win32ui, win32con, win32api

解决方案

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.

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.

Edit following exchange of comments with OP:

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值