Search code examples
cx-freeze

Quit cmd while exe is running


I have a .exe (PyQt5 + python3), the issue is that when I start the application, the cmd window is always initialized in the background. I want that the cmd window is not initialized.

This is the code that I used to convert to .exe:

import cx_Freeze
from cx_Freeze import *

setup(
    name = "interfaz",
    options = {'build_exe': {'packages': ['cv2', 'numpy']}},
    executables=[
        Executable(
            "interfaz.py",
        )
    ]
)

This is an image showing the app:


Solution

  • According to the cx_Freeze documentation, in order to avoid that the command prompt appears briefly under Windows, you need to:

    Freeze your application with the Win32GUI base [...]. This doesn’t use a console window, and reports errors in a dialog box.

    Try thus to modify your setup script as follows:

    import sys
    from cx_Freeze import setup, Executable
    
    # GUI applications require a different base on Windows (the default is for a console application).
    base = None
    if sys.platform == "win32":
        base = "Win32GUI"
    
    setup(name="interfaz",
          options={'build_exe': {'packages': ['cv2', 'numpy']}},
          executables=[Executable("interfaz.py", base=base)])