Wingware Python IDE

The Intelligent Development Environment for Python Programmers

Debugging Code Running Under Py2exe

Sometimes it is useful to debug Python code launched by an application
produced by py2exe -- for example, to solve a problem only seen when the
code has been packaged by``py2exe``, or so that users of the packaged
application can debug Python scripts that they write for the app.

When py2exe produces the *.exe, it strips out all but the modules it
thinks will be needed by the application and may miss any required by scripts
added after the fact. Also, py2exe runs in a slightly modified environment
(for example the PYTHONPATH environment is ignored). Both of these can
cause problems for Wing's debugger, but can be worked around with some
modifications to the packaged code, as illustrated in the following example:

To debug, an installation of Python matching the one used by py2exe must
be present and referenced by the EXTRA_PYTHONPATH environment variable.
This example assumes the installation of Python 2.5 at \Python25 was used
by py2exe.

The directory \Python25\Lib\site-packages\py2exe\samples\simple\dist is
where wingdbstub.py was placed; this can be altered as desired. Also,
WINGHOME should be altered to match the location where Wing is installed
and isn't needed at all if the value set in wingdbstub.py is correct (which
it usually will be if copied out of the Wing installation).

When trying this out, be sure to AcceptDebugConnections in Wing IDE by
clicking on the bug icon in the lower left of the main window. For more information
on using wingdbstub to debug, see Debugging Externally Launched Code

Enabling End Users to Debug

The above example is geared at the primary developers trying to find bugs in packaged code.
If the packaged application is one that allows the end user to write add-on scripts
and they want to debug these in Wing's debugger, then the importwingdbstub in the
above example should be replaced with the following imports: