.app made using PyInstaller closes straight away?

前端 未结 4 1333
[愿得一人]
[愿得一人] 2021-02-09 03:47

I have attempted to convert my python program into a .app using PyInstaller. The actual code runs fine through IDLE, but everytime I try and run the newly converted .app, it clo

4条回答
  •  遥遥无期
    2021-02-09 04:07

    I had the same problem as you even though I knew my code wasn't supposed to close immediately since it waited for user_input. When I ran my code from the terminal using python my_script.py the program would run fine.

    Here is how I fixed it:

    I reinstalled pyinstaller using:

    pip install pyinstaller
    

    I think that this was my main thing because the first time I installed it, I believe my antivirus prevented some of the components from installing correctly and when I reinstalled it, it probably patched in the holes.

    I also tried a different command-line command. I explicitly stated for the final .exe to open a console and keep it open using the -c flag. Note: On Windows, this option will have no effect if the first script is a ‘.pyw’ file. It looked like this:

    pyinstaller -c -F -i cm_icon.ico console_monopoly.py 
    

    the -F flag was to bundle everything into one .exe instead of having a lot of files surrounding my .exe in the dist/ folder.

    the -i flag is for adding an icon to my program.

    Hope this helps!

提交回复
热议问题