Question: Here's the code that I'm trying to run:

```
import pyautogui
r=pyautogui.locateOnScreen('C:\Users\David\Desktop\index.png',grayscale=False)
print r

```

Answer: 
It has to be a pixel-perfect match in order to be found. To allow for any sort of deviance you can invoke a confidence parameter.

For example:

```
loc = pyautogui.locateOnScreen(image, grayscale=True, confidence=.5)

```

However, in order to use the confidence parameter you have to have opencv\_python installed. This is easy to install with pip:

```
./python -m pip install opencv_python

```

After that is in place, you should be able to account for minor differences.
Before

```
import pyautogui
image = '9.png'
loc = pyautogui.locateOnScreen(image, grayscale=True, confidence=.5)
print (loc)

```

Error:

```
None
>>>

```

Solution

```
import pyautogui
import time
time.sleep(5)
image = '9.png'
loc = pyautogui.locateOnScreen(image, grayscale=True, confidence=.5)
print (loc)

```

Summary: Just add this two lines:

```
import time
time.sleep(5)

```

Output

```
Box(left=1686, top=248, width=70, height=47)
>>> 
import time
time.sleep(5)

```