From: Sean F <wsf...@ea...> - 2004-06-03 19:01:20
|
What do I need to do to build my script as a COM server with py2exe? As a learning tool, I'm using the code in the "Quick Start to Server side COM" documentation included with win32all, saved as testcom.py # testcom.py class HelloWorld: _reg_clsid_ = "{1B6DDB9E-5817-4BD8-9085-625DBB6304C9}" _reg_desc_ = "Python Test COM Server" _reg_progid_ = "Python.TestServer" _public_methods_ = ['Hello'] _public_attrs_ = ['softspace', 'noCalls'] _readonly_attrs_ = ['noCalls'] def __init__(self): self.softspace = 1 self.noCalls = 0 def Hello(self, who): self.noCalls = self.noCalls + 1 # insert "softspace" number of spaces return "Hello" + " " * self.softspace + who if __name__=='__main__': # ni only for 1.4! import win32com.server.register win32com.server.register.UseCommandLine(HelloWorld) When I run this script, the server is registered, and I can call it from other apps. Exactly the behavior I want. So, now I want to build this with py2exe, so I built the following setup script: # setup.py from distutils.core import setup import py2exe setup(com_server=["testcom.HelloWorld"]) When I run "python setup.py py2exe", it fails: Traceback (most recent call last): File "setup.py", line 4, in ? setup(com_server=["testcom.HelloWorld"]) File "c:\python23\lib\distutils\core.py", line 149, in setup dist.run_commands() File "c:\python23\lib\distutils\dist.py", line 907, in run_commands self.run_command(cmd) File "c:\python23\lib\distutils\dist.py", line 927, in run_command cmd_obj.run() File "c:\python23\lib\site-packages\py2exe\build_exe.py", line 187, in run self.find_needed_modules(mf, required_files, required_modules) File "c:\python23\lib\site-packages\py2exe\build_exe.py", line 809, in find_needed_modules mf.import_hook(mod) File "c:\python23\lib\modulefinder.py", line 125, in import_hook m = self.load_tail(q, tail) File "c:\python23\lib\modulefinder.py", line 191, in load_tail raise ImportError, "No module named " + mname ImportError: No module named testcom.HelloWorld I can clearly see what I am doing wrong - com_server needs to be module.Class, but my script is not a module. I've tried putting testcom.py into site-packages - when I do, I'm able to import it as a module, but the setup script fails with the same error. Any suggestions? Thanks - Sean F |