赞
踩
刚认识了pyautogui
,浅浅写一段自动准备jupyter的程序
import pyautogui #import pyperclip import time def open_jupyter(): print('Opening jupyter...') time.sleep(1) try: location = pyautogui.locateOnScreen(r"D:\STEFANOS\python\tools\auto\icons\jupyter.png",confidence=0.8) print(location) pyautogui.click(location) except pyautogui.ImageNotFoundException: print("Sorry I cannot locate Jupyter") time.sleep(3) def new(): print('newing...') time.sleep(1) try: location = pyautogui.locateOnScreen(r"D:\STEFANOS\python\tools\auto\icons\new.png",confidence=0.8) print(location) pyautogui.click(location) except pyautogui.ImageNotFoundException: print("Sorry I cannot locate 'new'") time.sleep(1) def python3(): print('newing python3...') time.sleep(1) try: location = pyautogui.locateOnScreen(r"D:\STEFANOS\python\tools\auto\icons\python3.png",confidence=0.8) print(location) pyautogui.click( ) except pyautogui.ImageNotFoundException: print("Sorry I cannot locate 'python3'") time.sleep(1) open_jupyter() new() python3()
报错:
第一类:unicode编码问题
OSError: Failed to read D:\STEFANOS\python oolsuto\icons\jupyter.png because file is missing, has improper permissions, or is an unsupported or invalid format
[ WARN:0@463.089] global loadsave.cpp:241 cv::findDecoder imread_(‘D:\STEFANOS\python oolsuto\icons\jupyter.png’): can’t open/read file: check file path/integrity
SyntaxError: (unicode error) ‘unicodeescape’ codec can’t decode bytes in position 232-233: truncated \UXXXXXXXX escape
写在前面:复制路径快捷键Ctrl+Shift+C
方法1:在路径前加r
location = pyautogui.locateOnScreen(r"D:\STEFANOS\python\tools\auto\icons\jupyter.png")
方法2:写成双斜杠\\
location = pyautogui.locateOnScreen("D:\\STEFANOS\\python\\tools\\auto\\icons\\jupyter.png")
方法3:改成/
location = pyautogui.locateOnScreen("D:/STEFANOS/python/tools/auto/icons/jupyter.png")
第二类:图像识别问题
raise ImageNotFoundException # Raise PyAutoGUI’s ImageNotFoundException.
ImageNotFoundException
可以降低图片‘信任度’,但建议在confidence=0.8
这样,
否则,比如会把jupyter识别成blender(无语了
第三类:写着写着就不见了的问题
python:ocal variable ‘xxx’ referenced before assignment
KeyboardInterrupt
欢迎解答
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。