pyautogui: Getting AttributeError: module 'pyscreeze' has no attribute 'locateOnWindow' on import

When attempting import pyautogui, I get the following error message and traceback:

Traceback (most recent call last):

  File "<ipython-input-1-fa2587ca3a04>", line 1, in <module>
    import pyautogui

  File "/usr/lib/python3.9/site-packages/pyautogui/__init__.py", line 221, in <module>
    locateOnWindow.__doc__ = pyscreeze.locateOnWindow.__doc__

AttributeError: module 'pyscreeze' has no attribute 'locateOnWindow'

I have checked the contents of pyscreeze/__init__.py, not just on my computer, but as it currently appears in the pyscreeze repository as well, and there really is no locateOnWindow function/class/etc. contained in it.

The problem might have been introduced by this commit about 2-3 months ago. Strangely, however, I have not been able to find anyone else on the web experiencing it.

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 9
  • Comments: 15 (1 by maintainers)

Commits related to this issue

Most upvoted comments

Hi Everyone! I hope everyone is doing well. It looks like there is an easy fix for this one.

https://github.com/asweigart/pyautogui/blob/5e4acb870f2e7ce0ea1927cc5188bc2f5ab7bbbc/pyautogui/__init__.py#L221

Here on this line we just need to change

locateOnWindow.__doc__ = pyscreeze.locateOnWindow.__doc__

To This:

locateOnWindow.__doc__ = pyscreeze.locateOnScreen.__doc__

Update this and your inputs will work. The locateOnWindow changed to locateOnScreen.

++@asweigart, FYI

Tested on: Windows Version	10.0.19042 Build 19042
Current Python:        3.9.2
Current PyAutoGUI:     0.9.53

The file location for me was: ‘C:\Users\{UserName}\AppData\Roaming\Python\Python39\site-packages\pyautogui\init.py’

Do not look in the C:\Program Files\Python39 folders

You should update pyscreeze to at least 0.1.28. to fix this error.

pip3 install pyscreeze -U

I’ve got the same error. I call the pyautogui.locateOnScreen function, but result is the error below.

AttributeError: module 'pyscreeze' has no attribute 'locateOnWindow'.

There is NO locateOnWindow function on pyscreeze, but pyscreeze.locateOnWindow is used on pyautogui.locateOnWindow. I think this is the reason.

https://github.com/asweigart/pyautogui/blob/5e4acb870f2e7ce0ea1927cc5188bc2f5ab7bbbc/pyautogui/__init__.py#L219

https://github.com/asweigart/pyscreeze/blob/0446e87235e0079f591f0c49ece7d487dedc2f9a/pyscreeze/__init__.py#L350

Hi Everyone! I hope everyone is doing well. It looks like there is an easy fix for this one.

https://github.com/asweigart/pyautogui/blob/5e4acb870f2e7ce0ea1927cc5188bc2f5ab7bbbc/pyautogui/__init__.py#L221

Here on this line we just need to change

locateOnWindow.__doc__ = pyscreeze.locateOnWindow.__doc__

To This:

locateOnWindow.__doc__ = pyscreeze.locateOnScreen.__doc__

Update this and your inputs will work. The locateOnWindow changed to locateOnScreen.

++@asweigart, FYI

Tested on: Windows Version	10.0.19042 Build 19042
Current Python:        3.9.2
Current PyAutoGUI:     0.9.53

The file location for me was: ‘C:\Users`{UserName}`\AppData\Roaming\Python\Python39\site-packages\pyautogui*init*.py’

Do not look in the C:\Program Files\Python39 folders Man thankyou so much

I run into this problem today and it was due to a newer pyautogui version with old pyscreeze. A less relaxed condition on the dependency (https://github.com/asweigart/pyautogui/blob/master/setup.py#L36) would have avoided it. Upgrading pyscreeze solved the issue for me.