See the custom-boot-script option at is still run, but your custom boot script is run immediately after so you can override anything it has done.


On Thu, Sep 1, 2011 at 8:13 AM, Marko Loparic <> wrote:

Is there a way to override without replacing the file in the py2exe installation directory?

Here is my version of I wrote it to have the stderr into the popup screen instead of into a log file:

import sys
if sys.frozen == "windows_exe":
    class Stderr(object):
        softspace = 0
        _file = None
        _alert = sys._MessageBox
        def print_error(self):
            text = 'Captured stderr:\n%s' % self._file.getvalue()
            self._alert(0, text)
        def write(self, text, alert=None, fname=None):
            if self._file is None:
                from StringIO import StringIO
                self._file = StringIO()
                import atexit
        def flush(self):
    sys.stderr = Stderr()
    del sys._MessageBox
    del Stderr

    class Blackhole(object):
        softspace = 0
        def write(self, text):
        def flush(self):
    sys.stdout = Blackhole()
    del Blackhole
del sys

This worked fine in a test I did by replacing in  c:/Python26/Lib/site-packages/py2exe/.

Thanks a lot,

Note1: The reasons I have for not generating a log file are

1) The executable is in a folder where the users don't have the permission to write. I could have changed the log directory in boot_common but I couldn't imagine an alternative directory which would be safe to create a log file. We could perhaps use %TEMP%, but I believe that users could be afraid to look there for log files...

2) I believe that it is easier for a user to send us the capture of the screen (in our experience every user knows how to do this) than to look for a log file in a directory (%TEMP% or another).

The inconvenience of the proposed approach could be to have a very big popup if there are too many messages are sent to stderr. But I my case I believe that this is unlikely to happen, because -- after parsing the command line, opening the logging handlers and creating the output directory where several logs and output files go -- our application redirects stderr to a file in this output directory. So the mechanism in is important only for the startup (i.e. to the errors that might happen before this redirection) and should not contain more information than a traceback in the case of a unforeseen exception.

Note 2: In order to test it I just wrote a with an exception:
raise RuntimeError("test")

and a standard
from distutils.core import setup
import py2exe


Special Offer -- Download ArcSight Logger for FREE!
Finally, a world-class log management solution at an even better
price-free! And you'll get a free "Love Thy Logs" t-shirt when you
download Logger. Secure your free ArcSight Logger TODAY!
Py2exe-users mailing list