Search code examples
pythonpyautogui

Why can't pyautogui find the picture?


import pyautogui
    
button7location = pyautogui.locateOnScreen('picturee.png')
print("finished")

The picture works perfect in a HTML file i created.

Th Error My files


Solution

  • Digging into the source code, we are directed from pyautogui to pyscreeze where we can see the following block of code in the location functions.

        if isinstance(needleImage, (str, unicode)):
            # 'image' is a filename, load the Image object
            needleFileObj = open(needleImage, 'rb')
            needleImage = Image.open(needleFileObj)
    

    In short, you need the image to be in the same directory as the one you're launching the script from.

    Link to source