2012-05-11 12 views
0

私はすでにこの質問の解決策を見て、他の人が投稿したことを試みました。私はpy2exeを実行すると、今エラー1053 Pythonで書かれたウィンドウサービスを起動するとき

running py2exe 
*** searching for required modules *** 
Traceback (most recent call last): 
    File "C:\Python27\Scripts\distutils-setup.py", line 5, in <module> 
    setup(service=["C:\Python27\Scripts\dev.py"]) 
File "C:\Python27\lib\distutils\core.py", line 152, in setup 
    dist.run_commands() 
File "C:\Python27\lib\distutils\dist.py", line 953, in run_commands 
    self.run_command(cmd) 
File "C:\Python27\lib\distutils\dist.py", line 972, in run_command 
    cmd_obj.run() 
File "C:\Python27\lib\site-packages\py2exe\build_exe.py", line 243, in run 
    self._run() 
File "C:\Python27\lib\site-packages\py2exe\build_exe.py", line 296, in _run 
    self.find_needed_modules(mf, required_files, required_modules) 
File "C:\Python27\lib\site-packages\py2exe\build_exe.py", line 1274, in 
find_needed_modules 
    mf.import_hook(mod) 
File "C:\Python27\lib\site-packages\py2exe\mf.py", line 719, in import_hook 
    return Base.import_hook(self,name,caller,fromlist,level) 
File "C:\Python27\lib\site-packages\py2exe\mf.py", line 136, in import_hook 
    q, tail = self.find_head_package(parent, name) 
File "C:\Python27\lib\site-packages\py2exe\mf.py", line 204, in find_head_package 
    raise ImportError, "No module named " + qname 
ImportError: No module named dev 

:私は以下の結果を得た

from distutils.core import setup 
import py2exe 

setup(console=["dev.py"]) 

from distutils.core import setup 
import py2exe 

setup(service=["dev.py"]) 

へ:あるユーザーがしようとするから私のsetup.pyファイルを変更すると言いました"コンソール"私のセットアップスクリプトでは正常に動作しますが、サービスが開始せず、エラーが表示されます。セットアップスクリプトでpy2exeを "service"と実行するとpy2exeが実行されず、自分のモジュールが見つからないことがわかります。

py2exeを解像度なしで再インストールしようとしました。私はまた、変更しようとしています

def SvcDoRun(self): 
    servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE, 
          servicemanager.PYS_SERVICE_STARTED, 
          (self._svc_name_,'')) 

def SvcDoRun(self): 
    self.ReportServiceStatus(win32service.SERVICE_RUNNING) 
    win32event.WaitForSingleObject(self.hWaitStop, win32event.INFINITE) 

にどちらかの違いはありませんでした。誰も助けてくださいね?ここで私が取り組んでいることがあります。サーバーを監視し、60秒ごとにテキストファイルを吐き出して、指定した分にサーバーを監視します。あなたとガルが与えるどんな助けも素晴らしいでしょう。

import win32serviceutil 
import win32service 
import win32event 
import servicemanager 
import socket 
import wmi 
import _winreg 
from time import sleep 
import os 

class SrvMonSvc (win32serviceutil.ServiceFramework): 
_svc_name_ = "SrvMonSvc" 
_svc_display_name_ = "Server Monitor" 

def __init__(self,args): 
    win32serviceutil.ServiceFramework.__init__(self,args) 
    self.hWaitStop = win32event.CreateEvent(None,0,0,None) 
    socket.setdefaulttimeout(60) 

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

def SvcDoRun(self): 
    servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE, 
          servicemanager.PYS_SERVICE_STARTED, 
          (self._svc_name_,'')) 
    self.main() 

def main(self): 
    host = wmi.WMI(namespace="root/default").StdRegProv 
    try: 
     result, api = host.GetStringValue(
     hDefKey = _winreg.HKEY_LOCAL_MACHINE, 
     sSubKeyName = "SOFTWARE\Server Monitor", 
     sValueName = "API") 
     if api == None: 
      raise Exception 
     else: 
      pass 
    except: 
     exit() 

    while 1 == 1: 
     with open("C:/test.txt", "wb") as b: 
      computer = wmi.WMI(computer="exsan100") 
      for disk in computer.Win32_LogicalDisk (DriveType=3): 
       name = disk.caption 
       size = round(float(disk.Size)/1073741824, 2) 
       free = round(float(disk.FreeSpace)/1073741824, 2) 
       used = round(float(size), 2) - round(float(free), 2) 
       for mem in computer.Win32_OperatingSystem(): 
        a_mem = (int(mem.FreePhysicalMemory)/1024) 
       for me in computer.Win32_ComputerSystem(): 
        t_mem = (int(me.TotalPhysicalMemory)/1048576) 
        u_mem = t_mem - a_mem 
       for cpu in computer.Win32_Processor(): 
        load = cpu.LoadPercentage 
       print >>b, api 
       print >>b, name 
       print >>b, size 
       print >>b, used 
       print >>b, t_mem 
       print >>b, u_mem 
       print >>b, load 
     b.close() 
     date_list = [] 
     stamp = time.strftime("%c",time.localtime(time.time())) 
     date_list.append(stamp) 
     name = re.sub(r"[^\w\s]", "",date_list[0]) 
     os.rename("C:/test.txt", ("C:/%s.txt" % name)) 

     try: 
      sleep(60.00) 
     except: 
      exit() 

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

答えて

1

元の問題から進んだことはありますか?私はPythonサービスに似た問題を抱えていて、 'System Path'(ユーザパスではない)が完全ではなかったのでDLLが見つからないことがわかりました。

コマンドプロンプトから-debugを指定してpythonservice.exeを実行すると、正しいPATH環境変数が使用されたため問題はありませんでしたが、サービスがシステムサービスとしてインストールされている場合は、システムパス変数にすべてのパス必要なDLL(MSVC、Python、System32)が必要です。私にとっては、PythonのDLLパスが欠けていたのですが、その後は再び動作しました。

関連する問題