[python-win32] Problems py2exe and Windows Services...

Sergej Pioch sergej.pioch at rz.uni-freiburg.de
Mon Sep 1 10:51:19 EDT 2003


Hello everybody,

I have certain problems building a windows executable fileset from a 
python windows service using py2exe. Before going any further with the 
description of the problem I have to tell you, that I am pretty new to 
python.

I use the Activestate Activepython distrib version 2.2.2 build 224 on 
Windows XP (for development).

I wrote the following UPS-Service in Python (should run on Windows2000 
and 2003 Servers). Here is the source:

------
# ZebrAPClient.py
#
# Service to look for an UPS caused shutdown


import win32serviceutil
import win32service
import win32event
from win32file import *
import win32api
import os
import socket




class ZebrAPClient(win32serviceutil.ServiceFramework):
    _svc_name_ = 'ZebrAPClient'
    _svc_display_name_ = 'ZebrAPClient'
    def __init__(self, args):
        win32serviceutil.ServiceFramework.__init__(self, args)
        self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)
    def SvcStop(self):
        self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
        win32event.SetEvent(self.hWaitStop)
    def SvcDoRun(self):
        Directory = '\\\\Path_to\\batch.file'
        X=1
        while X==1:
            rc = win32event.WaitForSingleObject(self.hWaitStop, 1)
            if rc==win32event.WAIT_OBJECT_0:
                break
            else:
                try:
                    Content = CreateFile(
                        Directory,
                        GENERIC_READ,
                        FILE_SHARE_READ,
                        None,
                        OPEN_EXISTING,
                        0,
                        None )
                    Action = ReadFile(Content, 256)
                    Content.Close()
                except win32api.error, (code, function, message):
                    continue
                if Action[0]==0:
                    os.system(Action[1]) # Hier bitte mehrzeilige 
Befehlentgegennahme einfügen!
                    X=0
                else:
                    continue
               

               
if __name__ == '__main__':
    win32serviceutil.HandleCommandLine(ZebrAPClient)
-----

It works really good. Now I want to generate a binary package for easier 
distribution to the servers ( in this case: without installing the whole 
python environment on every server). At google I found the tool 'py2exe' 
which I try to use. I wrote the following script 'setup.py':

-----
from distutils.core import setup
import py2exe

setup(name='ZebrAPClient',
      description="Get UPS commands to control servers",
      version='0.9.0',
      scripts=['ZebrAPClient.py'])
-----

In addition I use this 'setup.cfg':

----
[py2exe]
service=ZebrAPClient
optimize=2
excludes=perfmon
version_companyname = XXXXXXXXXXXXX
version_filedescription = UPS Control Service
version_fileversion = 0.9.0
version_legalcopyright = XXXXXXXXXXXXXXXXX
version_legaltrademarks = ZebrAPClient
version_productname = ZebrAPClient
version_productversion = 0.9.0
---

Now  I try to build the package with the following command:

'setup.py py2exe -s ZebrAPClient'

And here's the output:

----
running py2exe
running build
running build_scripts
not copying ZebrAPClient.py (up-to-date)
running install_scripts
not copying build\scripts-2.2\ZebrAPClient.py (output up-to-date)
+----------------------------------------------------
| Processing script ZebrAPClient.py with py2exe-0.4.1
+----------------------------------------------------
Searching modules needed to run 'ZebrAPClient.py' on path:
['C:\\Documents and Settings\\this.PROFILE\\My 
Documents\\ZebrAPC\\build\\bdist.win32\\winexe\\lib\\Python22\\Lib\\site-packages', 
'C:\\Documents and Settings\\this.PROFILE\\My Documents\\ZebrAPC',
'C:\\Python22\\Lib\\site-packages\\Pythonwin', 
'C:\\Python22\\Lib\\site-packages\\win32', 
'C:\\Python22\\Lib\\site-packages\\win32\\lib', 
'C:\\Python22\\Lib\\site-packages', 'C:\\Python22\\DLLs', 'C:\
\Python22\\lib', 'C:\\Python22\\lib\\lib-tk', 'C:\\Python22']
Traceback (most recent call last):
  File "C:\Documents and Settings\this.PROFILE\My 
Documents\ZebrAPC\setup.py", line 7, in ?
    scripts=['ZebrAPClient.py'])
  File "C:\Python22\lib\distutils\core.py", line 138, in setup
    dist.run_commands()
  File "C:\Python22\lib\distutils\dist.py", line 893, in run_commands
    self.run_command(cmd)
  File "C:\Python22\lib\distutils\dist.py", line 913, in run_command
    cmd_obj.run()
  File "C:\Python22\Lib\site-packages\py2exe\build_exe.py", line 604, in run
    mf.import_hook(f)
  File "C:\Python22\Lib\site-packages\py2exe\tools\modulefinder.py", 
line 126, in import_hook
    q, tail = self.find_head_package(parent, name)
  File "C:\Python22\Lib\site-packages\py2exe\tools\modulefinder.py", 
line 180, in find_head_package
    raise ImportError, "No module named " + qname
ImportError: No module named pywintypes
----

The command 'setup.py bdist --formats=wininst' works fine but does of 
course not lead to the desired result.


Anyone any idea?


Best regards


Sergej




More information about the Python-win32 mailing list