Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1019755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:03:47+00:00 2026-05-16T11:03:47+00:00

The way I currently add an executable for my Python-based GUI is this: setup(

  • 0

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 ;).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T11:03:47+00:00Added an answer on May 16, 2026 at 11:03 am

    Alright, I investigated a bit in the setuptools source code and it all boils down to a bug 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 statement 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 the else statement is not executed. The problem is that new_header[2:-1] in my case was "C:\Program Files (x86)\Python26\pythonw.exe" (with the quotes!), so os.path.exists said 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.pyw

    #!pythonw.exe
    
    # This script will be executed by the primary Python version that is installed, which might as well be Python 3. But
    # we want to execute it with the Python version that belongs to this script's path. So let's do a major hack:
    
    import os
    import sys
    import subprocess
    
    if sys.argv[-1] == "magic":
        from dogsync_frontend.launcher import main
        main()
    else:
        # The CPython folder hierarchy is assumed here (<installation>\pythonw.exe, <installation>\Scripts\<thisscript>)
        subprocess.Popen([os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "pythonw.exe")),
                          __file__,
                          "magic"])
    

    File dogsync-frontend.exe

    Automatically 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.py

    from setuptools import __file__ as setupToolsFilename
    
    if os.name == "nt":
        # Use a customized (major hack) start script instead of the one that gets automatically created by setuptools
        # when the "gui_scripts" parameter is used. This way, we don't need setuptools installed in order to run DogSync.
        shutil.copy2(os.path.join(os.path.dirname(setupToolsFilename), "gui.exe"),
                     "build-environment/windows-scripts/dogsync-frontend.exe")
        startScripts = dict(scripts = ["build-environment/windows-scripts/dogsync-frontend-script.pyw",
                                       "build-environment/windows-scripts/dogsync-frontend.exe"])
    else:
        # For Linux, I don't have a solution to remove the runtime dependency on setuptools (yet)
        startScripts = dict(entry_points = {"gui_scripts" : ['dogsync-frontend = dogsync_frontend.launcher:main']})
    
    setup(<other options>,
          **startScripts)
    

    With this setup, the exe/pyw files are copied to <python installation>\Scripts (on Windows) and starting dogsync-frontend.exe will run the pyw script without a console. Since setuptools did not get any updates for years, this solution is still working.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 516k
  • Answers 516k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This is a good solution and in certain situations can… May 16, 2026 at 6:48 pm
  • Editorial Team
    Editorial Team added an answer The problem is that you want to give an error… May 16, 2026 at 6:48 pm
  • Editorial Team
    Editorial Team added an answer From the amsmath documentatiom (amsldoc.pdf): You can suppress the number… May 16, 2026 at 6:48 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I'm currently looking for a way to add data to an already compiled ELF
I currently have a single solution with a single project and this generates executable
Currently my web.config has this: <appSettings> <add key=UserName /> <add key=DBServer /> <add key=DBUserName
I'm currently using the Mootools Element constructor method to dynamically add a new row
I am currently building a web application for my work and you can add
I'd like to add native date pickers to my application, which currently uses a
Currently I'm storing the settings for my custom addins in the registry but this
I am trying to find a way to decode the REG_BINARY value for HKLM\Software\Microsoft\Ole\DefaultLaunchPermission
Currently I have solution A that contains a domain layer base and solution B
I have a perl script (or any executable) E which will take a file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.