How to distribute Python COM applications?

Gregory P. Smith greg at electricrain.com
Thu May 31 15:11:37 EDT 2001


> >I am also starting to look at all installation aspects of Python COM. 
> >(registry items, DLLs, etc.) If I succeed, I'll let people know.
> >
> >So far I have succeeded in distributing Python COM client 
> >applications.
> >
> >It's the Python COM server part that is complicated. I know py2exe or 
> >Gordon installer are not enough, but besides that, more registry 
> >tweaking and DLL handling are needed.
> 
> Actually, it's more a problem with the arrangement of responsibilities.
> 
> Your typical Python COM server defines a class and has some register / 
> unregister logic under the "if __name__ == '__main__':" code. So it's both 
> a script (when registering / unregistering) and a module (when attached 
> through COM). If you just freeze your class, all you'll get is the register 
> / unregister code, and it won't create the right entries.
> 
> There *is* a script which runs (when you use out-of-process): it's 
> win32com/server/localserver.py. As proof of concept, I hacked up 
> localserver.py so that I got localserver.exe which could serve up my COM 
> class. By manually tweaking the registry, I got it working (out-of-
> process). So I know this stuff is possible, it's just that generalizing and 
> automating it is a considerable amount of work.

It mostly took reading win32com and the likes, but creating a com
server as a standalone executable that can both register/unregister
itself -and- act as the com server executable worked.  Just be sure to
force "pythoncom.frozen = 1" in your code before calling
"win32com.server.register.UseCommandLine(mycominterfaceobject)"

Them have the main code check for --register or --unregister command
line arguments to call that instead of
win32com.server.localserver.main() as the default.  (and you can make
it runnable via non-com if applicable to your application by checking
for other parameters and not calling localserver.main() but whatever
other code you want to).

> [And I'm not sure that in-process is possible, mainly because with in-
> process I don't think I have enough control over installation and search 
> paths.]

Hmm.. in process seemed to work fine for us, though that is not at all
what we wanted, we explicitly specified local server as its good to
not have one application's fatal error bring down the other.

-- 
Gregory P. Smith   gnupg/pgp: http://electricrain.com/greg/keys/
                   C379 1F92 3703 52C9 87C4  BE58 6CDA DB87 105D 9163




More information about the Python-list mailing list