Well, I did a little research on the setuptools source code, and it all boils down to the error in setuptools (easy_install.py):
# On Windows/wininst, add a .py extension and an .exe launcher if group=='gui_scripts': ext, launcher = '-script.pyw', 'gui.exe' old = ['.pyw'] new_header = re.sub('(?i)python.exe','pythonw.exe',header) else: ext, launcher = '-script.py', 'cli.exe' old = ['.py','.pyc','.pyo'] new_header = re.sub('(?i)pythonw.exe','python.exe',header) if os.path.exists(new_header[2:-1]) or sys.platform!='win32': hdr = new_header else: hdr = header
The last if decides whether the path pythonw.exe or python.exe is written to shebang "frontend-script.pyw". Since this shebang is evaluated by the created EXE file, it is necessary that the else not executed. The problem is that new_header[2:-1] in my case was "C: \ Program Files (x86) \ Python26 \ pythonw.exe" (with quotes!), Therefore os.path.exists said that it does not exist because of quotes.
I will try to get this fixed by the setuptools developers. The remaining problem will be the absolute path of pythonw.exe. If I create a Windows / MSI installer, shebang will contain my pythonw.exe path ("C: \ Program Files (x86) \ Python26 \ pythonw.exe"), but the user could install Python in "C: \ Python26". I will report the final solution after I reported this problem.
I posted this two years ago, I'm sorry I have not yet proposed my solution. Not sure if there is a more modern solution (maybe distribute offers something), but here is what I used then (copying)
dogsync-frontend-script.pyw
#!pythonw.exe
dogsync-frontend.exe file
Automatically copied from <python installation>\lib\site-packages\setuptools\gui.exe (see below). This file will automatically execute script <name of EXE>-script.py[w] if I remember correctly.
Setup.py setup.py
from setuptools import __file__ as setupToolsFilename if os.name == "nt":
With this installation, exe / pyw files are copied to <python installation>\Scripts (on Windows), and running dogsync-frontend.exe will run the pyw script without a console. Since setuptools has not received any updates for many years, this solution still works.