I wrote a simple script in Python 3.9.5 and converted it to .exe by running
pyinstaller --onefile -w myscript.py
My script works perfectly fine when I launched it from the python file, but it doesn't work. When I clicked on the .exe file located in the dist folder. It says Failed to execute script myscript
I tried creating a much simpler script with only print("Hello World!")
and converted it to .exe with the exact same steps - It works perfectly fine... I have no idea why my first script did not work.
Here's the code I created:
import pyautogui
from pynput import keyboard
import time
import threading
text = pyautogui.prompt('Text: ')
interval = pyautogui.prompt('Interval: ')
def spam():
while running:
pyautogui.press('enter')
pyautogui.write(text)
pyautogui.press('enter')
time.sleep(float(interval))
running = False
def on_press(key):
global running
if key == keyboard.Key.f1:
running = running ^ True
if running:
t = threading.Thread(target=spam)
t.start()
with keyboard.Listener(on_press=on_press) as listener:
listener.join()