64

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?

starball
  • 20,030
  • 7
  • 43
  • 238
dfreeze
  • 655
  • 1
  • 5
  • 6
  • 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 Answers6

129

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.

Epoc
  • 7,208
  • 8
  • 62
  • 66
Stephan
  • 16,509
  • 7
  • 35
  • 61
  • 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
  • 1
    Note that the `--no-console` switch doesn't have any effect on *NIX systems. – Epoc Mar 06 '17 at 10:19
26

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.

Blender
  • 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
17

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.

PileUpOKpull
  • 301
  • 2
  • 6
5
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.

Suparno
  • 111
  • 1
  • 6
3

This command works fine

pyinstaller -F -w yourfilename.py

This hides the black console window.

Simas Joneliunas
  • 2,890
  • 20
  • 28
  • 35
1

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