Search code examples
pythonloggingpy2exedistutils

Py2Exe generate log file


My problem is that py2exe is generating a log file when I run. It doesn't generate because I have an error when running the program. At the log file there is the standard console print out!

How can I do it that no log file would generate?

here my py2exe setup code:

from distutils.core import setup
import py2exe, sys, os
sys.argv.append('py2exe')
setup(
    options = {'py2exe': {'bundle_files': 1, 'compressed': True}},
    windows = [{'script': "run.py"}],
    zipfile = None
)

Solution

  • In GUI applications, Py2exe redirects sys.stderr to a log file and sys.stdout to an object that ignores all writes. To avoid the log file, do this in your program at the top of the main module:

    import sys
    sys.stderr = sys.stdout
    

    Or, let py2exe create a console application by using the console keyword instead of windows in setup.py.