简体   繁体   English

带有Python和py2exe的Windows服务

[英]Windows services with Python and py2exe

I need some help with converting a python windows service using py2exe. 我需要一些使用py2exe转换python Windows服务的帮助。

Let me explain the problem. 让我解释一下这个问题。 I have a python service, which works, no problems here. 我有一个python服务,可以正常工作,这里没有问题。 I used py2exe to turn it into an executable file. 我使用py2exe将其转换为可执行文件。 I tested it by replacing the python version of the service with this one and it works with no problems too. 我通过用该服务替换python版本的服务进行了测试,它也没有问题。

But when I move the exe version of the service to another computer, it will register with the service manager but won't start with the error: "The system cannot find the file specified". 但是,当我将服务的exe版本移动到另一台计算机时,它将在服务管理器中注册,但不会以错误开头:“系统找不到指定的文件”。 The missing file is one of the modules I've written. 丢失的文件是我编写的模块之一。

I played with this a bit and went back to the machine where I used py2exe and where the exe version of the service works. 我稍微玩了一下,然后回到使用py2exe的机器以及该服务的exe版本可以运行的机器。 I removed everything python related, everything py2exe created but the "dist" folder, everything I could think of that was related with the python version of the service. 我删除了所有与python相关的内容,删除了py2exe创建的所有内容,但删除了“ dist”文件夹,我想到的所有内容均与该服务的python版本相关。 The exe version still worked (altho I removed, amongst others, the very files that were supposedly missing on the other machine). exe版本仍然有效(除其他外,我还删除了其他机器上据说缺少的文件)。

Tried a bunch of different things but cant get the exe version to work. 尝试了一堆不同的东西,但无法使exe版本正常工作。 If any of you guys have any ideas, I'd really appreciate it. 如果你们有什么想法,我将不胜感激。

PS: I do have the c++ runtime installed on the target machine. PS:我确实在目标计算机上安装了c ++运行时。 You can't register the service without it and as I said, I can register it, it just won't run. 没有它,您将无法注册该服务,正如我所说,我可以注册它,它将无法运行。

Even if you converted the .py script to an exe, the service still uses the python interpreter to run the service code itself. 即使您将.py脚本转换为exe,该服务仍会使用python解释器来运行服务代码本身。 if you open "Services" and look at the service properties you should see something like - Path to executable: "C:\\Python27\\lib\\site-packages\\win32\\PythonService.exe" 如果打开“服务”并查看服务属性,您应该会看到类似-可执行文件的路径:“ C:\\ Python27 \\ lib \\ site-packages \\ win32 \\ PythonService.exe”

i'm guessing the other computer doesnt have python installed on it. 我猜另一台计算机上没有安装python。 if you want to be able to run that service on a machine without installing python you need to do something like This ,or you can also do it using cx_freeze 如果您希望能够在机器上运行该服务而无需安装python,则需要执行类似This的操作 ,也可以使用cx_freeze进行操作

http://www.py2exe.org/index.cgi/py2exeAndWindowsServices http://www.py2exe.org/index.cgi/py2exeAndWindowsServices

There are some notes in there about modules conflicting with windows system dlls. 那里有一些有关与Windows系统dll冲突的模块的说明。 He had a problem because he had a module called version and import version caused the app to error out. 他有一个问题,因为他有一个名为version和import version的模块,导致该应用程序出错。

You can try importing win32traceutil as the first thing in your service. 您可以尝试将win32traceutil导入为服务中的第一件事。 This should allow you to run the win32traceutil console app to display any stdout/stderr output from the service. 这应该允许您运行win32traceutil控制台应用程序以显示该服务的所有stdout / stderr输出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM