【问题标题】:Windows service compile with pyinstaller issueWindows 服务编译时出现 pyinstaller 问题
【发布时间】:2015-07-06 13:59:19
【问题描述】:

我已经实现了一个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)

【问题讨论】:

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

标签: python compilation windows-services pyinstaller


【解决方案1】:

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

C:\Python27\Lib\site-packages\win32

【讨论】:

    【解决方案2】:

    最后我解决了这个问题,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__,))])
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多