Python Windows服务编译与pyinstaller问题

Python Windows服务编译与pyinstaller问题,python,compilation,windows-services,pyinstaller,Python,Compilation,Windows Services,Pyinstaller,我已经实现了一个windows服务,这个服务在使用pyinstaller编译之前没有问题,但是在服务启动命令上,它给出了1053错误 Windows服务代码: import sys import win32service import win32event import socket import win32api import win32serviceutil class AppServerSvc(win32serviceutil.ServiceFramework): _svc_n

我已经实现了一个windows服务,这个服务在使用pyinstaller编译之前没有问题,但是在服务启动命令上,它给出了1053错误

Windows服务代码:

import sys
import win32service
import win32event
import socket
import win32api
import win32serviceutil


class AppServerSvc(win32serviceutil.ServiceFramework):
    _svc_name_ = "test"
    _svc_display_name_ = "test"
    _stoped = False

    def __init__(self, *args):
        win32serviceutil.ServiceFramework.__init__(self, *args)
        self.stop_event = win32event.CreateEvent(None, 0, 0, None)

    def SvcStop(self):
        self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
        win32event.SetEvent(self.hWaitStop)
        self._stoped = True

    def SvcDoRun(self):
        self.ReportServiceStatus(win32service.SERVICE_RUNNING)
        self.main()

    def main(self):
        while True:
            if self._stoped:
                break
            pass

if __name__ == '__main__':
    win32serviceutil.HandleCommandLine(AppServerSvc)

最后我解决了这个问题,windows服务中的一个引用的链接断开了。这是py2exe的正确配置,解决了我的问题:

opts = {'py2exe': {
'dll_excludes': ['libzmq.pyd', 'OLEAUT32.dll', 'USER32.dll', 'SHELL32.dll', 'ole32.dll',
                 'MSVCP90.dll', 'ADVAPI32.dll', 'NETAPI32.dll', 'WS2_32.dll', 'GDI32.dll',
                 'VERSION.dll', 'KERNEL32.dll', 'WINSPOOL.DRV', 'mfc90.dll', 'ntdll.dll'],
'includes': ['UserList', 'UserString', 'commands', 'zmq.backend.cython'],
'dist_dir': "dist"
}}

setup(service=[service], options=opts, zipfile=None,data_files=[(os.path.join(os.getcwd(), 'dist'), (zmq.libzmq.__file__,))])

要在生成的exe pyInstaller中使用我的win32serviceutil.ServiceFramework类,我需要向包含exe的目录中添加一些.pyd文件,例如win32service.pyd和win32event.pyd。假设您使用了库的标准安装路径,可以在以下位置找到这些文件:

C:\Python27\Lib\site packages\win32


1.发布关于那个错误的所有信息。2.您使用的是哪个Python版本?3.您执行哪些步骤来编译它?4.您的目标是编译它还是运行它?如果它不是作为服务运行,它是否成功运行?