簡體   English   中英

Python 3.10:LocaOnScreen 問題

[英]Python 3.10: LocaOnScreen Issues

我是 python 的新手,我正在使用 python 3.10.1。 下面是我正在嘗試運行的程序片段。

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)

這是我運行程序時的錯誤:

  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

為什么我會收到此錯誤消息?

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. 安裝 python 3.7.3 2. https://filehippo.com/download_python/3.7.3/
  2. 將 python 3.7.3 添加到安裝路徑
  3. 像這樣安裝這個庫:
    • pip3.7 安裝 pywin32
    • pip3.7 安裝鍵盤
    • pip3.7 安裝 pyautogui
    • pip3.7 安裝 opencv-python
  4. Go 到文件資源管理器並創建一個新文件夾'隨意命名'並將你的 png'stickman.png' 文件放在那里並創建一個新的 python 文件
  5. 在 vs 代碼中打開“隨意命名”
  6. 關閉並打開 vs 代碼 select python 3.7.3 在 vscode 作為enterpreter
  7. 粘貼上面的代碼並調試它

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM