nssm后启动python exe服务时遇到错误 [英] Facing error when python exe service is started after nssm
问题描述
我有一种情况,我必须在 NSSM 中将 python.exe 作为服务运行.为了测试,我创建了 .exe 文件,其中只有 import pandas as pd .我在 NSSM 中成功创建了服务.但是当我启动该服务时出现错误 windows 无法在本地计算机上启动该服务该服务没有返回错误.
I have a situation where i have to run a python.exe as a service in NSSM. To test, I have created .exe file which has only import pandas as pd in it. I created the service in NSSM successfully. But when I start the service I get error windows could not start the service on local computer the service did not return an error.
我还能做些什么来解决这个问题?
What else can I do to tackle this problem?
相信我,我已经尝试过堆栈溢出的所有解决方案.
Trust me I have tried all solutions in stack overflow.
- 我在启动服务时关闭了 cmd.
- 将所有控制权交给网络服务
推荐答案
在 Program Files 或其他公共文件夹(如果尚未安装)中安装 Python.
Install Python in Program Files or another public folder if not already.
如果您的服务作为 NETWORK SERVICE 运行,请使用 psexec 作为网络服务:
If your service are running as the NETWORK SERVICE run CMD with psexec as the NETWORK SERVICE:
psexec -i -u "nt authority\network service" cmd.exe
在cmd中检查你是否可以运行python并导入pandas.
In cmd check if you can run python and import pandas.
由于服务不能有窗口,所以您需要以某种方式检查程序的结果.例如将异常重定向到文件:
Since services can't have windows you need to somehow check result of your program. For example redirect exception to a file:
try:
import pandas
# do something
except Exception as e:
with open(r'c:/service_output.txt', 'wt+') as fd:
fd.write(repr(e))
这篇关于nssm后启动python exe服务时遇到错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!