【Pyautogui自动准备jupyter】附上报错合集

刚认识了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

欢迎解答

  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值