Hide the console of an .exe file created with PyInstaller

Question:

I want to make my program executable.
I used TkInter to write the GUI, and I read somewhere that you have to save your file as .pyw to hide the console when the program is executed.
The problem is that after making it an executable with PyInstaller, the console shows up again, even though the file converted was .pyw.
How can I hide the console also in the .exe file?

Asked By: Matteo Secco

||

Answers:

What are you using to make the executable?

If you use py2exe and you use:

setup(windows=[pythonscriptnamehere])

in the setup script instead of:

setup(console=[pythonscriptnamehere])

it will run the executable without launching a terminal in the background.

Answered By: liamhawkins

Did you try --windowed command line flag ?

Answered By: Maurice Meyer

You can just save the file with .pyw extension and you can just use pyinstaller --onefile Filename.pyw
I think you renamed it. You save it as .pyw don’t rename it.
The screenshot are below:
enter image description here

enter image description here

enter image description here

Output:

enter image description here

But it takes a while to open.
Thank you
-Levers

Answered By: EpicPy

From The PyInstaller Documentation:

Using a Console Window

By default the bootloader creates a command-line console (a terminal
window in GNU/Linux and Mac OS, a command window in Windows). It gives
this window to the Python interpreter for its standard input and
output. Your script’s use of print and input() are directed here.
Error messages from Python and default logging output also appear in
the console window.

An option for Windows and Mac OS is to tell PyInstaller to not provide
a console window. The bootloader starts Python with no target for
standard output or input. Do this when your script has a graphical
interface for user input and can properly report its own diagnostics.

As noted in the CPython tutorial Appendix, for Windows a file
extention of .pyw suppresses the console window that normally appears.
Likewise, a console window will not be provided when using a
myscript.pyw script with PyInstaller.

Answered By: Bugs Bunny

Rather than saving/renaming/changing the extension to .pyw, you can just add --noconsole to the command line and use the standard .py file with it and this would hide that console window.

Example:

We have a file named GUI_name.py in our folder that uses Tkinter. Now we could easily create .exe file that doesn’t show the console window by typing pyinstaller --onefile --noconsole GUI_name.py in cmd.

enter image description here

Answered By: Danish366
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.