Using py2exe to wrap a service?

Larry Bates larry.bates at websafe.com
Wed Sep 20 09:20:53 EDT 2006


Maria.Reinhammar at accalon.com wrote:
> I have an app using active_directory.py and the std module asyncore in
> a Windows Service.
> Works perfectly!
> That is, until I try to use py2exe to create a standalone (need to
> avoid installing the entire Python etc. on the target system).
> 
> When I try to start the installed Service, the system tells me it
> terminates prematurely
> and in the event log I find:
> The instance's SvcRun() method failed
>   File "win32serviceutil.pyc", line 785, in SvcRun
>   File "XXProxySvc.pyc", line 126, in SvcDoRun
>   File "XXProxySvc.pyc", line 94, in setup
>   File "D:\projects\XXProxy\DB.py", line 54, in loadFromAD
>   File "active_directory.pyc", line 402, in search
>   File "active_directory.pyc", line 398, in root
>   File "active_directory.pyc", line 371, in AD
>   File "active_directory.pyc", line 378, in _root
>   File "win32com\client\__init__.pyc", line 73, in GetObject
>   File "win32com\client\__init__.pyc", line 88, in Moniker
> pywintypes.com_error: (-2147221020, 'Invalid syntax', None, None)
> 
> The offending line is:
> import active_directory as AD
> ...
> for item in AD.search ("objectCategory='Person'"):
> ...
> 
> I.e. the call to AD.search() is the entry point to the problem.
> 
> The setup.py is (pretty straight forward..):
> from distutils.core import setup
> import py2exe
> 
> class Target:
>     def __init__(self, **kw):
>         self.__dict__.update(kw)
>         # for the versioninfo resources
>         self.version = "0.9.0"
>         self.company_name = "My Company"
>         self.copyright = "My Company (c)"
>         self.name = "FilterProxy"
> 
> ################################################################
> # a NT service, modules is required
> myservice = Target(
>     # used for the versioninfo resource
>     description = "AD Driven Mail Filter",
>     # what to build.  For a service, the module name (not the
>     # filename) must be specified!
>     modules = ["ProxySvc"]
>     )
> 
> excludes = []
> setup(options = {"py2exe": {# create a compressed zip archive
>                             #"compressed": 1,
>                             #"optimize": 2,
>                             "excludes": excludes
>                             }
>                  },
>       service=[myservice]
>       )
> 
> 'elp! Pleeeez!
> 

You may want to post this on gmane.comp.python.py2exe also.

I'm going to try to guess what the problem is, but it is a little hard to tell
from here.  py2exe does its best to find all the modules required to create the
.exe.  Sometimes modules do dynamic imports, etc. of modules that "fool" py2exe.
 I'm guessing that this is the case and that you will need to manually include
the missing module.  Most such errors seem to fall into this category.  Hope
this at least points you in the correct direction.

-Larry Bates



More information about the Python-list mailing list