当前位置:   article > 正文

【Pyautogui自动准备jupyter】附上报错合集,已解决

【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()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46

报错:

第一类: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")

  • 1
  • 2

方法2:写成双斜杠\\

location = pyautogui.locateOnScreen("D:\\STEFANOS\\python\\tools\\auto\\icons\\jupyter.png")

  • 1
  • 2

方法3:改成/

location = pyautogui.locateOnScreen("D:/STEFANOS/python/tools/auto/icons/jupyter.png")

  • 1
  • 2

第二类:图像识别问题

raise ImageNotFoundException # Raise PyAutoGUI’s ImageNotFoundException.
ImageNotFoundException

可以降低图片‘信任度’,但建议在confidence=0.8这样,
否则,比如会把jupyter识别成blender(无语了

第三类:写着写着就不见了的问题

python:ocal variable ‘xxx’ referenced before assignment

KeyboardInterrupt

欢迎解答

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小桥流水78/article/detail/970071
推荐阅读
相关标签
  

闽ICP备14008679号