Is there any way to run a Python script without a command shell momentarily appearing? Naming my files with the ".pyw" extension doesn't work.
Try using the Python's pythonw.exe
executable to start your script.
In Windows OSes, executables that are console applications (python.exe
with out the w
is a console app) are run showing a console window; in the other hand regular Windows applications do not spawn that black console window.
You can find the details about these two executables in this old question: pythonw.exe or python.exe?
And about Windows different types of applications here: Difference between Windows and Console application
In all python installs since 2.5 (and possibly earlier), if the install has been done properly, .py
files are associated to python.exe
and .pyw
files are associated to pythonw.exe
If the associations have been tampered with, or overridden for a particular user, that may be different.
Run the following command in a cmd:
ftype | find "pythonw"
assoc | find ".pyw"
I get:
Python.NoConFile="D:\Program Files\Python27\pythonw.exe" "%1" %*
.pyw=Python.NoConFile
If you don't have that, you can do several things to fix that:
if you're not administrator of your machine, you can associate .pyw
files to pythonw.exe
. Minor problem with that, you have to alter the registry key afterwards to add the extra arguments or dropping a parameter on your .pyw file won't take it into account (it's seldom used but still)
[HKEY_CLASSES_ROOT\Python.NoConFile\shell\open\command]
@="\"L:\\Portable_Python_2.7.3.1\\App\\pythonw.exe\" \"%1\" %*"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With