简体   繁体   English

无法在 Visual Studio python 中导入 win32api 和 win32con

[英]cannot import win32api and win32con in visual studio python

i am trying to import win32api and win32con into my python project .我正在尝试将 win32api 和 win32con 导入到我的 python 项目中。 i have installed pypiwin32 and pywin32 from PyPi , but when i try to import win32api , win32con , i get a green underline under win32api and win32con , and when i hover over the green line , a pop-up says "unresolved import 'win32api'"我已经从 PyPi 安装了 pypiwin32 和 pywin32,但是当我尝试导入 win32api、win32con 时,我在 win32api 和 win32con 下看到一个绿色下划线,当我将鼠标悬停在绿线上时,弹出窗口显示“未解决的导入‘win32api’”

here's the code :这是代码:

import keyboard
import time
import win32api , win32con
# tile 1 x : 380  y :   650
# tile 2 x : 450  y :   650
# tile 3 x : 530  y :   650
# tile 4 x : 600  y :   650

def click(x,y):
    win32api.SetCursorPos((x,y))
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0,0)
    time.sleep(0.01)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0,0)


while keyboard.is_pressed("q") == False :
    if pyautogui.pixel(380,500)[0] == 0:
        click(380,500)
       
    if pyautogui.pixel(450,500)[0] == 0:
        .click(450,500)
        
    if pyautogui.pixel(530,500)[0] == 0:
        click(530,500)
        
    if pyautogui.pixel(600,500)[0] == 0:
        click(600,500) 

Okay, so, how did you installed it?好的,那你是怎么安装的? I'm trying as you said, with PyPI in VS 2019 and...我正在按你说的那样尝试,在 VS 2019 中使用 PyPI 并且......

No packages for it :S .没有它的包 :S 。 Suggests to install with pip, but it fails so...建议使用 pip 安装,但它失败了...

So, your manager as I figured out, is pip... are you sure you have those installed?所以,正如我发现的那样,你的经理是 pip ......你确定你安装了那些吗?

As @Quinn said, is the package installed?正如@Quinn 所说,是否安装了软件包? like in the cmd...就像在 cmd ...

pip install win32con
pip install win32api

Other case can be that you probably didn't check the "ADD TO PATH" during Python installation.其他情况可能是您在 Python 安装过程中可能没有检查“添加到路径”。 If so, you should probably reinstall Python and make sure that "ADD TO PATH" Check box is checked, and try using PIP to install the packages.如果是这样,您可能应该重新安装 Python 并确保选中“添加到路径”复选框,然后尝试使用 PIP 安装软件包。

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

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