1

I have a small timer script that displays information through a pygame window. I can run it fine as a script. When I convert it to an .exe with pyinstaller, it still runs fine, but when I exit by pressing the "x" at the top of the window, i get an error message "Failed to execute script myscript." I assume it is a problem with my closing code.

If it matters, I am running pyinstaller with options -F (make a single file) and -w (run without a console window)

I have added new parameters to the close code as suggested in other threads here. My current exit code is listed below.

for event in pygame.event.get(): 
    if event.type == pygame.QUIT:
        pygame.display.quit()
        pygame.quit()
        exit()

I just want it to close cleanly without an error

2 Answers2

2

Solved it, I was not importing sys correctly. exit() showed up as a keyword in IDLE, so I thought it was a basic command. I added the line "import sys" to the top and changed the closing line to "sys.exit()" and it is working as expected.

0

Use

import sys

#insert code here


sys.exit()

instead of

exit()

The exit() command is used to exit the python shell. See here

blackbrandt
  • 2,010
  • 1
  • 15
  • 32