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?
-
related: [Python - how can i hide the windows command prompt screen when the script is running?](http://stackoverflow.com/q/24799155/4279) – jfs Feb 28 '16 at 19:53
6 Answers
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.
-
I am not printing anything to the console window anyway, so this doesn't help. Thanks for trying. – dfreeze Jul 11 '13 at 16:17
-
"there is, of course, the ugly console output window" did you mean you want to close it? or prevent it from opening? if so I misunderstood – Stephan Jul 11 '13 at 16:19
-
yes, That's what I meant. Would `os.system('exit')` work, or would that just close the program? – dfreeze Jul 11 '13 at 16:23
-
@dfreeze no, click on the link in my edit and control-f for "--noconsole" For a detailed guide – Stephan Jul 11 '13 at 16:26
-
1Note that the `--no-console` switch doesn't have any effect on *NIX systems. – Epoc Mar 06 '17 at 10:19
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.

- 289,723
- 53
- 439
- 496
-
I am running PyInstaller 2.0, which means I simply type `python pyinstaller.py MYCODE.pyw` into cmd in the correct directory and it does the rest for me, including making the `.spec` file. Do I need to interrupt the program somewhere and execute this line? If so, how? – dfreeze Jul 11 '13 at 16:20
-
Thanks for --onefile suggestion @Blender. $ python pyinstaller.py --noconsole --onefile yourprogram.py – Zohab Ali Nov 11 '17 at 16:00
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.

- 301
- 2
- 6
-
2--noconsole didn't work for me, but changing the spec file did. Thank you. – sawyermclane Apr 26 '18 at 16:19
-
changing spec file did not worked in my case, at least reversing, making True, window taceback and debug =True – xlmaster Oct 21 '22 at 07:46
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.

- 111
- 1
- 6
-
I thought there was no way to get just a single .exe! Thank you very much +1 – RukshanJS Mar 19 '20 at 18:12
-
-
-F stands for onefile, this command creates a one-file bundled executable. See the full documentation. https://pyinstaller.readthedocs.io/en/stable/usage.html – Suparno Jun 10 '21 at 03:54
This command works fine
pyinstaller -F -w yourfilename.py
This hides the black console window.

- 2,890
- 20
- 28
- 35

- 31
- 2
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

- 61
- 6