简体   繁体   English

无法将 win32gui 和 win32ui 模块导入我在 Phyton 3.8 32 位上的项目

[英]Can't Import win32gui and win32ui modules to my project on Phyton 3.8 32-bit

I am trying to get screenshot in Phyton 3.8.我正在尝试在 Phyton 3.8 中获取屏幕截图。 When I search in google for the fastest way I found this link.当我在谷歌搜索最快的方式时,我找到了这个链接。 Fastest way to take a screenshot with python on windows 在 Windows 上使用 python 截屏的最快方法

There is some module needed to install in this code.在此代码中需要安装一些模块。 I tired to install them with command below.我厌倦了用下面的命令安装它们。

pip install pywin32 pip 安装 pywin32

After that command I could import win23con to my project.在该命令之后,我可以将win23con导入到我的项目中。 But when I try to import win32gui and win32ui gave error in import lines.但是当我尝试导入win32guiwin32ui在导入行中出现错误。 I shared error titles in below.我在下面分享了错误标题。

import win32con导入 win32con
import win32gui #No module named 'win32gui' import win32gui #没有名为'win32gui'的模块
import win32ui #No module named 'win32ui' import win32ui #没有名为'win32ui'的模块

Screenshot for error from PyCharm来自 PyCharm 的错误截图

After some research on google.经过对谷歌的一些研究。 I fount this answer in stackoverflow.我在 stackoverflow 中找到了这个答案。 https://stackoverflow.com/a/44065593/17257421 https://stackoverflow.com/a/44065593/17257421

If I understand corretly, I have to use Phyton-32bit version to use pywin32 module.如果我理解正确,我必须使用 Phyton-32bit 版本才能使用 pywin32 模块。 I swith my project to Phyton 3.8 32-bit.我将我的项目切换到 Phyton 3.8 32 位。 But still I get same error.但我仍然得到同样的错误。

Where I try select Phyton Version for my Project我在哪里尝试为我的项目选择 Phyton 版本

pywin32 works just fine under 64-bit Python, so no, you do not need to use a 32-bit one -- switch to 64-bit Python on a 64-bit system, unless you specifically need 32-bit one for some specific reason. pywin32 在 64 位 Python 下工作得很好,所以不,你不需要使用 32 位的——在 64 位系统上切换到 64 位 Python,除非你特别需要 32 位的某个特定的原因。 That does not seem to be the case here, though.不过,这里似乎并非如此。

Also, if you have import-errors, it may be because your library is incomplete or old:此外,如果您有导入错误,可能是因为您的库不完整或旧:

  • check what version you have installed at the moment with pip list -- the currently latest version as of writing this is 302.使用 pip list 检查您目前安装的版本 - 在撰写本文时当前最新版本是 302。
  • run "pip uninstall pywin32" to remove whatever you have installed运行“pip uninstall pywin32”以删除您已安装的任何内容
  • check that it didn't leave any leftover pywin32-related files under your Python libraries (use the snippet below to check the path, if you don't know where to look)检查它没有在您的 Python 库下留下任何剩余的 pywin32 相关文件(如果您不知道在哪里查看,请使用下面的代码段检查路径)
  • after clearing out any leftovers, try installing pywin32 again and see if it works correctly now清除所有剩余物后,再次尝试安装 pywin32,看看它现在是否正常工作

How to get the path to Python's libraries:如何获取 Python 库的路径:

import win32con, os
print(os.path.dirname(win32con.__file__).rsplit("\\", 2)[0])

It'll spit out something akin to eg: 'C:\\Users\\werecatf\\pywin.venv\\lib\\site-packages'它会吐出类似的东西,例如:'C:\\Users\\werecatf\\pywin.venv\\lib\\site-packages'

The actual path will be different for you, but look there for anything related to "win32" and move those out somewhere else or delete them.实际路径对您来说会有所不同,但在那里查找与“win32”相关的任何内容并将它们移到其他地方或删除它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM