The way I currently add an executable for my Python-based GUI is this:
setup(
# ...
entry_points = {"gui_scripts" : ['frontend = myfrontendmodule.launcher:main']},
# ...
)
On Windows, this will create “frontend.exe” and “frontend-script.pyw” in Python’s scripts folder (using Python 2.6). When I execute the EXE file, a console window is shown but the PYW file works correctly without showing one.
So my question is: How can I make the EXE file execute the program without the console window? The solution should work on Linux, too (don’t suggest py2exe ;).
Alright, I investigated a bit in the setuptools source code and it all boils down to a bug in setuptools (easy_install.py):
The last
ifstatement decides whether pythonw.exe’s or python.exe’s path is written into the shebang of "frontend-script.pyw". As this shebang is evaluated by the created EXE file, it is necessary that theelsestatement is not executed. The problem is thatnew_header[2:-1]in my case was "C:\Program Files (x86)\Python26\pythonw.exe" (with the quotes!), soos.path.existssaid it does not exist because of the quotes.I will try to get this corrected by the setuptools developers. The remaining problem will be the absolute pythonw.exe path. If I create a Windows setup/MSI installer, the shebang will contain my pythonw.exe path ("C:\Program Files (x86)\Python26\pythonw.exe") but the user might have installed Python in "C:\Python26". I’ll report the final solution after I’ve reported this problem.
I posted this over two years back, sorry that I didn’t yet offer my solution. Not sure if there is any more modern solution (probably distribute offers something), but here’s what I used back then (copy-pasted):
File
dogsync-frontend-script.pywFile
dogsync-frontend.exeAutomatically copied from
<python installation>\lib\site-packages\setuptools\gui.exe(see below). This file will automatically execute the script<name of EXE>-script.py[w]if I remember correctly.File
setup.pyWith this setup, the exe/pyw files are copied to
<python installation>\Scripts(on Windows) and startingdogsync-frontend.exewill run the pyw script without a console. Since setuptools did not get any updates for years, this solution is still working.