4

I have an application that prints a few things to the console upon running. But as a standalone the executable doesn't print anything to the console?

The setup.py script looks like this:

import sys
from cx_Freeze import setup, Executable

setup(
    name = "My App",
    version = "1.0",
    options = {
        "build_exe" : {
            "include_files": ['MyImgs']
        },
    },
    executables = [Executable("Main.py", base = "Win32GUI")]
)

On the command line I run the following: py setup.py build

I then find the executable and run: Main.exe.

What I am missing for some reason is any print() statements. Is there something I need to include in the setup script for this to happen?

Max
  • 2,072
  • 5
  • 26
  • 42

1 Answers1

6

If you use the "Win32GUI" base, then Windows does not make available stdout and stderr. You will need to redirect those yourself to some other location (such as a file). If you use the "Console" base then stdout and stderr are available and print() will work as expected -- but you will see a console created for you if you haven't run it from a console in the first place!

Anthony Tuininga
  • 6,388
  • 2
  • 14
  • 23
  • what exactly does `base` do? And does setting `base="Console"` allow me to run this executable in both Windows and Mac – Max Jul 18 '16 at 14:12
  • 1
    The setting "base" defines the base code that runs the Python code (see the source/bases section of the source). Console is standard on all platforms. Only Windows differentiates between "console" and "GUI". So yes, using "Console" will let you run on both Windows and Mac. – Anthony Tuininga Jul 18 '16 at 14:35