【问题标题】:Facing error when python exe service is started after nssm在 nssm 之后启动 python exe 服务时遇到错误
【发布时间】:2021-03-09 05:30:05
【问题描述】:

我有一种情况,我必须在 NSSM 中将 python.exe 作为服务运行。为了测试,我创建了 .exe 文件,其中只有 import pandas as pd。我在 NSSM 中成功创建了服务。但是当我启动服务时,我收到错误windows could not start the service on local computer the service didn't return an error

我还能做些什么来解决这个问题?

相信我,我已经尝试过堆栈溢出的所有解决方案。

  1. 我在启动服务时关闭了 cmd。
  2. 将所有控制权交给网络服务

【问题讨论】:

  • Pandas 不是默认包,因此您可能仅在您的用户帐户下安装了它,并且用户 NETWORK SERVICE 无法访问您的用户包或 appdata 中的整个 python 安装.
  • 如何解决?

标签: python windows windows-services scheduled-tasks nssm


【解决方案1】:
  1. Program Files 或其他公用文件夹中安装 Python(如果尚未安装)。

  2. 如果您的服务作为 NETWORK SERVICE 运行,则使用 psexec 作为 NETWORK SERVICE 运行 CMD:

     psexec -i -u "nt authority\network service" cmd.exe
    
  3. Install pandas 使用这个 cmd。

  4. 在cmd中检查是否可以运行python并导入pandas。

  5. 由于服务不能有窗口,您需要以某种方式检查程序的结果。例如将异常重定向到文件:

     try:
         import pandas
         # do something
     except Exception as e:
         with open(r'c:/service_output.txt', 'wt+') as fd:
             fd.write(repr(e))
    

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-14
    • 2020-03-07
    • 1970-01-01
    • 2022-08-14
    • 1970-01-01
    • 1970-01-01
    • 2019-11-12
    • 1970-01-01
    相关资源
    最近更新 更多