1

I have a GUI script run.py which i turned into a .exe file using pyinstaller. When I double click on the .exe file two windows are opened. First the main GUI of my script and second the empty black cmd window on background.

I saw on forums that saving run.py as run.pyw and then converting it into .exe file will solve the problem. But in my case the problem remains same.

Does anyone have any idea how to get rid of this empty cmd window on background when i run my .exe file?

Anudocs
  • 686
  • 1
  • 13
  • 54

2 Answers2

4

Start the script with with pythonw instead of python to avoid the shell showing up. This actually applies to Python 2.x and 3.x.

See pythonw.exe or python.exe?

If you would like to start the script by double clicking the file you can associate the file extension to be opened with pythonw.exe instead of python.exe. This will apply to all your *.py files!

Rightlick run.py, Open with, Choose another app, More apps, Look for another app on this PC. Locate your pythonw.exe - it's next to your python.exe. Then check the checkbox Always use this app to open .py files.

To avoid associating this behaviour with all your *.py files, change the extension of run.py to e.g .pyw and then apply the described steps.

If you don't know where your python.exe is but you can use it from the terminal then open PowerShell and enter (Get-Command pythonw.exe).Source to find out.

This only applies to your computer - if you want this to work on all machines you copy your file to, please see Fabrizios answer.

nitzel
  • 1,565
  • 14
  • 14
  • Sorry i didnt get you.I want to start the script which is converted into .exe file by double clicking on it. – Anudocs Apr 26 '19 at 14:52
  • You'll have to associate the file extension to be opened with `pythonw.exe` instead of `python.exe`. This will apply to all your `*.py` files (unless you rename your file to e.g. `*.pyw` before). Rightlick `run.pyw`, `Open with`, `Choose another app`, `More apps`, `Look for another app on this PC`. Locate your `pythonw.exe` - it's next to your `python.exe`. Then check the checkbox `Always use this app to open .pyw files`. – nitzel Apr 26 '19 at 15:15
  • Ah I see, sorry. My steps describe how to start a script without a terminal. No .exe-conversion involved – nitzel Apr 26 '19 at 15:24
2

try to build your file .exe with pyinstaller with the options --noconsole

https://pyinstaller.readthedocs.io/en/latest/usage.html#windows

Fabrizio
  • 46
  • 4