-1

I tried using py -m PyInstaller --onefile filename.py to compile my program. It did compile; but after running it, it opened a black console and quickly closed it before executing anything.

I have tried plenty of different methods, but none of them worked. Also sometimes it compiles the file, without executing it.

I tried using py -m PyInstaller --onefile filename.py.

I thought that after opening the .exe file the program will execute.

I'm using the latest version of Windows 11.

xihtyM
  • 240
  • 1
  • 2
  • 9
  • 1
    If it did compile, it is simply exiting to fast for you to see it. Or there is a bug with the compiler. If it is the first, just open a terminal and run the file directly in the terminal so it will not close, or add a time.sleep/input call at the end of the program. If it is the latter, just use a different compiler. – xihtyM Mar 07 '23 at 22:17
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. – Сергей Кох Mar 08 '23 at 06:01
  • Does this answer your question? [How can I convert a .py to .exe for Python?](https://stackoverflow.com/questions/41570359/how-can-i-convert-a-py-to-exe-for-python) – Code-Apprentice Mar 09 '23 at 04:57
  • How do you know that your code doesn't execute? A black console window means your code does in fact execute. It closes because the program finishes. – Code-Apprentice Mar 09 '23 at 04:59

1 Answers1

0

I looks like the program is converted to .exe successfully the problem is that your program exits after executing you can avoid it by running the program in command prompt or if you don't want to do that you can try putting input() at the end of your script this will make the program quit only when the user presses the enter key if this doesn't work for you. You can import time module and add time.sleep(3) at the end of your program this will make the program exit after 3 second change the time to your liking and it will be good.