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 found that if you program a pause of 1 or 2 seconds (using time.sleep), then it is able to locate the image. It also takes time for python to locate the image (my computer took about 5 seconds).