Why is the .exe file created by pyinstaller not working?

14,735

Try opening a command prompt and navigating to the folder you installed it. Then run it via flappybird.exe (or whatever you titled it) and check that the error doesn't show up within your terminal. It sounds like it hits an error that crashes it, but immediately closes before you can read the error. Therefore running it from terminal allows it to have a window that doesn't disappear and it can print an error message there if there is one (this may only tell you errors during startup though, I'm not sure). I typically prefer to use a GUI that has a section of text that updates and I can use this to essentially "print" statuses of my compiled programs into this box, perhaps you could use a similar technique? Best of luck!

update

With your code I was able to compile it and run it with no problems (using cx-freeze). My setup.py file was:

import sys
from cx_Freeze import setup, Executable

# Dependencies are automatically detected, but it might need fine tuning.
additional_modules = []

build_exe_options = {"includes": additional_modules,
                     "packages": ["pygame", "random", "sys", "pyglet"],
                     "excludes": ['tkinter'],
                     "include_files": ['icon.ico', 'res']}

base = None
if sys.platform == "win32":
    base = "Win32GUI"

setup(name="Flappy Bird",
      version="1.0",
      description="Flap around",
      options={"build_exe": build_exe_options},
      executables=[Executable(script="flappybird.py", base=base)])

You can get your executable working if you

  • pip install cx_freeze

  • copy/paste the code above into a file setup.py (placed right next to your script)

  • open folder in command prompt and run python setup.py build

You may need to run the command again if it fails (something to do with trying to read from a folder it hasn't made yet).

  • Now you have a new folder build and your executable is inside it!
Share:
14,735
Luap555
Author by

Luap555

Updated on June 26, 2022

Comments

  • Luap555
    Luap555 almost 2 years

    I built a simple "flappy bird" game with pygame and then tried to convert the .py script with pyinstaller into an .exe with pyinstaller flappybird.py. But when I try to execute the .exe, the command prompt and the game window open for about 2 seconds without displaying any errors and without showing anything from the game, which works fine when executed as python script via flappybird.pyin the command prompt. I am using the newest version of pyinstaller and I don´t have any idea why this isn´t working, since it worked like a charm with other games I wrote before.

    Thanks for your help ;D

  • Luap555
    Luap555 about 5 years
    Thank you for your reply, even if i start the exe via the console, no error shows up. Can you explain more accurate how you use an GUI? I don´t quite get what you mean.
  • Reedinationer
    Reedinationer about 5 years
    Would it be possible for you to link the source code or executable?
  • Luap555
    Luap555 about 5 years
    Can you try to convert it via pyinstaller? I will try it with cx_freeze later, i had problems installing it because visual c++ 14.0 was missing
  • Reedinationer
    Reedinationer about 5 years
    I'll leave it for somebody else to post a pyinstaller solution. I prefer cx_freeze because the developer (you) specifies what packages to include/exclude as well as any additional files/folders your program needs. pyinstaller on the other hand gets all the files itself (an incomplete list of supported packages: github.com/pyinstaller/pyinstaller/wiki/Supported-Packages), but can often encounter errors like discussed at pyinstaller.readthedocs.io/en/stable/…
  • Luap555
    Luap555 about 5 years
    Thank you anyways it worked after finally getting cx_freeze to work!
  • Reedinationer
    Reedinationer about 5 years
    @Luap555 Awesome! It's a pretty sweet game :) just needs maybe some adjusting with the flaps or gravity or something, seems a lot harder than the actual game was XD
  • Luap555
    Luap555 about 5 years
    Oh yes that's true😂