py2exe problem

Duncan Booth duncan at NOSPAMrcp.co.uk
Mon Jul 23 04:19:26 EDT 2001


Jay Parlar <jparlar at home.com> wrote in
news:mailman.995667696.25448.python-list at python.org: 

> One note: This program is intended to run as a COM local server
> (controlled by an IE comm band). Could that possibly be the problem?
> Does py2exe not take kindly to folks trying to use COM in their Python
> code? We're not even trying to run it with IE yet, there is a way to
> start it independently, but neither way will produce screen output on a
> machine that doesn't have Python installed.

There a few tricks you have to do to get py2exe running properly with COM
servers. This URL has a useful post from Thomas Heller with a working 
example (edit it to one line if it gets split in transit):
http://groups.google.com/groups?selm=9eag5l%241muh3%241%40ID-59885.news.df
ncis.de 

Also you will find life a lot easier if you avoid using the -w flag while 
you are trying to get your application working. Without -w everything 
should run visibly on the screen and you can see uncaught exceptions or put 
print statements where you wish (even if it is running as a COM server). 
Only after you can build the exe and run it successfully on another Python-
free machine should you consider using the -w flag.

Another thing I have found useful is that my code (which is based on the 
example referenced above) is wrapped in code that replaces sys.stdout and 
sys.stderr with a cStringIO file and also catches and prints exceptions 
(including any exceptions raised by importing the rest of my code).
the original stdout and stderr are restored during the call to 
localserver.main(), but otherwise at the end of the program I get any data 
written to stdout/stderr and, if there is any, it goes in a call to 
win32ui.MessageBox.
The effect of this is that the messages indicating the server was 
registered or unregistered are displayed in a popup box, but more 
importantly the stack backtraces telling me what failed are also shown when 
something goes wrong. 
(Actually the code is a bit more complex because I also found it useful to 
add a --quiet option to suppress the registration popups so that I could 
register the control quietly from the setup program.)

-- 
Duncan Booth                                             duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?



More information about the Python-list mailing list