2

I just wanted to ask your help with my problem below. My code is working perfectly but after converting it to .exe using PyInstaller, I will encounter FileNotFoundError: [WinError 2].

Kindly suggest how I can fix it.

FileNotFound:[WinError 2]

Code:

import pyautogui, time

try:
    while True:
        time.sleep(30)
        pyautogui.dragRel(1,0)
        pyautogui.dragRel(-1,0)

except KeyboardInterrupt:
    print('Done')
linusg
  • 6,289
  • 4
  • 28
  • 78
  • Do you convert it to a singlefile exe or a folder with the exe and some files? – linusg Sep 11 '16 at 13:59
  • I tried both but it wont work. – user6819230 Sep 11 '16 at 14:06
  • Continue testing with the folder executable first. Have you tried https://github.com/pyinstaller/pyinstaller/wiki/If-Things-Go-Wrong and https://github.com/pyinstaller/pyinstaller/wiki/How-to-Report-Bugs#make-sure-everything-is-packaged-correctly? – linusg Sep 11 '16 at 14:10

1 Answers1

1

I have the same problem with PyAutoGUI and PyInstaller and could not get the clicking to work. Moving the mouse and the image recognition seem to work though.

Thanks to this post right here I found a "workaround":

Instead of using the pyautogoi.click() method, I'm using a similar method from ctypes.

import ctypes

I exchanged the pyautogui.click() calls with

# see http://msdn.microsoft.com/en-us/library/ms646260(VS.85).aspx for details
ctypes.windll.user32.mouse_event(2, 0, 0, 0,0) # left down
ctypes.windll.user32.mouse_event(4, 0, 0, 0,0) # left up

For double clicking I just call those two methods twice.

Community
  • 1
  • 1
David
  • 554
  • 7
  • 9