Pyinstaller "Failed to execute script due to unhandled exception" Error

Viewed 2914

I made a simple program that works as a .py file, but when I use pyinstaller to make a .exe file, the command prompt opens and closes immediately. By screen recording opening the .exe, I was able to see the following error flash on the command prompt before it closed: "Failed to execute script "kahoot_spammer" due to unhandled exception!"

I am using pyinstaller --onefile kahoot_spammer.py to convert my .py to a .exe file. Here is the code in my program; which I plan on using at school to add a ton of users to the class Kahoot game:

from pynput.mouse import Button, Controller as mController
from pynput.keyboard import Key, Controller as kController
import time
mouse = mController()
keyboard = kController()

#ask user for the kahoot game pin, what name they want the fake players to have, and how many players to create
game_code = input("Game Code: ")
username = input("Username: ")
amount = input("Player Amount: ")

#delay the program so the user can switch to their browser with kahoot open
time.sleep(5)

#create players
for i in range(amount):
    #enter game pin
    mouse.position = (775, 500)
    mouse.click(Button.left, 1)
    keyboard.type(game_code)
    mouse.position = (775, 550)
    mouse.click(Button.left, 1)

    time.sleep(0.5)

    #enter username
    mouse.position = (775, 520)
    mouse.click(Button.left, 1)
    keyboard.type(username + str(i))
    mouse.position = (775, 570)
    mouse.click(Button.left, 1)

    time.sleep(0.2)

    #open new tab with kahoot ready to go
    keyboard.press(Key.ctrl)
    keyboard.press("t")
    keyboard.release(Key.ctrl)
    keyboard.release("t")
    keyboard.type("https://kahoot.it")
    keyboard.press(Key.enter)
    keyboard.release(Key.enter)

    time.sleep(1)

Does anyone know how I can fix this error, and have the program run as it should? The .pyc file that is created alongside the .exe works as it should; the command prompt stays open and the program functions as expected.

1 Answers

I would suggest using pyinstaller --onefile --debug=all kahoot_spammer.py to get more debug information.

In my specific case my application failed when importing a logging object associated with my GUI library Kivy. So I commented out the line in my code that turned logging off and it works now.

This link helped me: https://pyinstaller.readthedocs.io/en/stable/when-things-go-wrong.html

Related