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: 
I had the similar problem.

My fault was I had saved the compare picture as jpg first and then as png in MS paint.

Be sure to save the compare picture as png format. After this the Locate function worked for me.
I got this working by using the following:

```
r = None
while r is None:
    r = pyautogui.locateOnScreen('rbin.PNG', grayscale = True)
print icon_to_click + ' now loaded'

```

The key is to make grayscale = True.