开发者社区> 问答> 正文

python服务打包问题

用python做了一个Windows服务。 主要结构如下:

class Smonitoringdebug(): svc_name = "Smonitoringdebug"
svc_display_name = "Smonitoringdebug"
svc_description = "监控测试"

def SvcDoRun(self):
    cnxn  =  pyodbc.connect('DRIVER={SQL Server};SERVER=test;DATABASE=Smonitoring;UID=sa;PWD=1234567')
    cursor  =  cnxn.cursor()

    print("service is run....")
   try:
        while True:
                ……
                cursor.execute(……)
                cnxn.commit()

            time.sleep(100)
        cnxn.close()
    except Exception as e:
        cnxn.close()
        print(e)
        time.sleep(500)

def SvcStop(self):
    print("service is stop....")
    self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
    win32event.SetEvent(self.hWaitStop)
    self.run = False

if name == 'main': #win32serviceutil.HandleCommandLine(SmonitoringServer)
Smonitoringdebug().SvcDoRun()

通过python环境使用正常。 用pyinstaller打包
pyinstaller Smonitoringdebug.py

打包后安装服务出错:

Smonitoringdebug install Traceback (most recent call last): File "SmonitoringServer.py", line 177, in File "site-packages\win32\lib\win32serviceutil.py", line 544, in HandleCommandLine File "site-packages\win32\lib\win32serviceutil.py", line 485, in GetServiceClassString IndexError: list index out of range [18216] Failed to execute script SmonitoringServer

求解决方法,谢谢!

展开
收起
游客346nu2ci3cudy 2020-01-16 08:39:32 863 0
1 条回答
写回答
取消 提交回答
  • pyinstaller打包应该是有具体的操作的,建议看一下打包方式是否存在错误

    2020-03-25 16:26:52
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
From Python Scikit-Learn to Sc 立即下载
Data Pre-Processing in Python: 立即下载
双剑合璧-Python和大数据计算平台的结合 立即下载