简体   繁体   中英

Python 3.10: LocaOnScreen Issues

I'm new to python, and I'm using python 3.10.1. Below is a snippet of the program I am trying to run.

from pyautogui import *
import pyautogui
import time
import keyboard
import random
import win32api, win32con
while 1:
    if pyautogui.locateOnScreen ('stickman.png'):
        print ( " I Can see It " )
        time.sleep (0.5)
    else:
        print ( " I Can't see it " )
        time.sleep (0.5)

Here is the error when I run the program:

  File "C:/Users/menne/AppData/Local/Programs/Python/Python310/aa.py", line 9, in <module>
    if pyautogui.locateOnScreen ('stickman.png'):
  File "C:\Users\menne\AppData\Local\Programs\Python\Python310\lib\site-packages\pyautogui\__init__.py", line 175, in wrapper
    return wrappedFunction(*args, **kwargs)
  File "C:\Users\menne\AppData\Local\Programs\Python\Python310\lib\site-packages\pyautogui\__init__.py", line 213, in locateOnScreen
    return pyscreeze.locateOnScreen(*args, **kwargs)
  File "C:\Users\menne\AppData\Local\Programs\Python\Python310\lib\site-packages\pyscreeze\__init__.py", line 373, in locateOnScreen
    retVal = locate(image, screenshotIm, **kwargs)
  File "C:\Users\menne\AppData\Local\Programs\Python\Python310\lib\site-packages\pyscreeze\__init__.py", line 353, in locate
    points = tuple(locateAll(needleImage, haystackImage, **kwargs))
  File "C:\Users\menne\AppData\Local\Programs\Python\Python310\lib\site-packages\pyscreeze\__init__.py", line 207, in _locateAll_opencv
    needleImage = _load_cv2(needleImage, grayscale)
  File "C:\Users\menne\AppData\Local\Programs\Python\Python310\lib\site-packages\pyscreeze\__init__.py", line 170, in _load_cv2
    raise IOError("Failed to read %s because file is missing, "
OSError: Failed to read stickman.png because file is missing, has improper permissions, or is an unsupported or invalid format

Why am I receiving this error message?

from pyautogui import * 
import pyautogui 
import time 
import keyboard 
import random
import win32api, win32con

while 1:
    if pyautogui.locateOnScreen('stickman.png') == None:
        print("I can't see it")
        time.sleep(0.5)
    else:
        print("I am able to see it")
        time.sleep(0.5)
  1. install python 3.7.3 2. https://filehippo.com/download_python/3.7.3/
  2. add python 3.7.3 to the path in instalion
  3. install this libaries like that:
    • pip3.7 install pywin32
    • pip3.7 install keyboard
    • pip3.7 install pyautogui
    • pip3.7 install opencv-python
  4. Go to file explorer and creat a new folder 'name it as you like' and place there your png 'stickman.png' file and creat a new python file
  5. open 'name it as you like' in vs code
  6. close and open vs code select the python 3.7.3 in vscode as an enterpreter
  7. paste the code above and debug it

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