Getting rid of console output when freezing Python programs using Pyinstaller
Question:
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, there is, of course, the ugly console output window. I have successfully gotten rid of it by simply changing the extension of the file from .py to .pyw. When I freeze it using PyInstaller, it reappears again! Is there any way for me to fix this?
Answers:
Just add the --noconsole
flag:
$ python pyinstaller.py --noconsole yourprogram.py
You might want to use --onefile
as well, which creates a single .exe
file instead of a folder.
If you want to hide the console window, here is the documentation:
This is how you use the --noconsole
option
python pyinstaller.py --noconsole yourscript.py
If you need help using pyinstaller to get to the point where you need to use the --noconsole
option here is a simple tutorial for getting there.
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.
Pyinstaller -F --noconsole yourfilename.pyw
This will create a single .exe file
Pyinstaller --noconsole yourfilename.pyw
Using this you will get the .exe file along with all .dll and other necessary files in a folder.
This command works fine
pyinstaller -F -w yourfilename.py
This hides the black console window.
When you run your python script for executing the .exe file with pyintaller you would try this command to get rid of console window.
pyinstaller --onefile -w your_script.py
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, there is, of course, the ugly console output window. I have successfully gotten rid of it by simply changing the extension of the file from .py to .pyw. When I freeze it using PyInstaller, it reappears again! Is there any way for me to fix this?
Just add the --noconsole
flag:
$ python pyinstaller.py --noconsole yourprogram.py
You might want to use --onefile
as well, which creates a single .exe
file instead of a folder.
If you want to hide the console window, here is the documentation:
This is how you use the --noconsole
option
python pyinstaller.py --noconsole yourscript.py
If you need help using pyinstaller to get to the point where you need to use the --noconsole
option here is a simple tutorial for getting there.
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.
Pyinstaller -F --noconsole yourfilename.pyw
This will create a single .exe file
Pyinstaller --noconsole yourfilename.pyw
Using this you will get the .exe file along with all .dll and other necessary files in a folder.
This command works fine
pyinstaller -F -w yourfilename.py
This hides the black console window.
When you run your python script for executing the .exe file with pyintaller you would try this command to get rid of console window.
pyinstaller --onefile -w your_script.py