Search code examples
pythonpython-2.7attributeerrorpyautogui

python pyautogui AttributeError: 'module' object has no attribute 'size'


import pyautogui
import time

def pause():
    time.sleep(0.001)

while True:
    pyautogui.keyDown('down')


    time.sleep(5)

Gives me error

C:\Python27\python.exe E:/Python/win32/pythongui.py
Traceback (most recent call last):
  File "E:/Python/win32/pythongui.py", line 1, in <module>
    import pyautogui
  File "E:\Python\win32\pyautogui.py", line 45, in <module>
    screenWidth, screenHeight = pyautogui.size()
AttributeError: 'module' object has no attribute 'size'

Process finished with exit code 1

I don't understand why I get this error I don't even call attribute size and yesterday everything worked just fine. Today for some weird reason I keep getting this error. Code is exactly same as before when pyautogui worked.


Solution

  • Beacuse you set the file name to pyautogui.py, which apparently conflicts with the package you importing. change your file name and run again Refer this issue: https://github.com/Microsoft/vscode-python/issues/1588