Getting rid of console output when freezing Python programs using Pyinstaller

前端 未结 4 784
天命终不由人
天命终不由人 2020-11-27 14:03

I have recently written a fairly simple program for my grandfather using Python with GUI from Tkinter, and it works beautifully for what he will be using it for. However, th

4条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-27 14:30

    This is one of the first things that comes up in a search for this info, so I'd like to add what I found for release 3.2 of pyinstaller. If you've already packaged your script by running

    pyinstaller --onefile your_script.py
    

    or similar, you can edit the your_script.spec file to rid yourself of the console.

        exe = EXE(pyz,
              a.scripts,
              a.binaries,
              a.zipfiles,
              a.datas,
              name='main',
              debug=False,
              strip=False,
              upx=True,
              console=True )
    

    Simply change the console value to False. Then run:

    pyinstaller your_script.spec
    

    Additionally, if you make changes to your code, run the above command to have them reflected in the your_script.exe. I have found this useful for debugging various other issues.

提交回复
热议问题