简体   繁体   中英

cannot import win32api and win32con in visual studio python

i am trying to import win32api and win32con into my python project . 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'"

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...

No packages for it :S . Suggests to install with pip, but it fails so...

So, your manager as I figured out, is pip... are you sure you have those installed?

As @Quinn said, is the package installed? like in the cmd...

pip install win32con
pip install win32api

Other case can be that you probably didn't check the "ADD TO PATH" during Python installation. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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