使用 Python 和 py2exe 的 Windows 服务 [英] Windows services with Python and py2exe

查看:77
本文介绍了使用 Python 和 py2exe 的 Windows 服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些帮助来使用 py2exe 转换 python Windows 服务.

I need some help with converting a python windows service using py2exe.

让我解释一下这个问题.我有一个 python 服务,它可以工作,这里没有问题.我用 py2exe 把它变成了一个可执行文件.我通过用这个服务替换 python 版本来测试它,它也没有问题.

Let me explain the problem. I have a python service, which works, no problems here. I used py2exe to turn it into an executable file. I tested it by replacing the python version of the service with this one and it works with no problems too.

但是当我将服务的 exe 版本移动到另一台计算机时,它会向服务管理器注册但不会以错误启动:系统找不到指定的文件".丢失的文件是我编写的模块之一.

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". The missing file is one of the modules I've written.

我玩了一会儿,然后回到我使用 py2exe 和服务的 exe 版本工作的机器上.我删除了 python 相关的所有内容,py2exe 创建的所有内容,但dist"文件夹,我能想到的所有内容都与服务的 python 版本相关.exe 版本仍然有效(尽管我删除了其他机器上据称丢失的文件).

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. 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. 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. If any of you guys have any ideas, I'd really appreciate it.

P.S:我确实在目标机器上安装了 c++ 运行时.如果没有它,您将无法注册该服务,正如我所说,我可以注册它,但它无法运行.

P.S: I do have the c++ runtime installed on the target machine. You can't register the service without it and as I said, I can register it, it just won't run.

推荐答案

即使您将 .py 脚本转换为 exe,服务仍然使用 python 解释器来运行服务代码本身.如果您打开服务"并查看服务属性,您应该会看到类似 -可执行文件路径:"C:\Python27\lib\site-packages\win32\PythonService.exe"

Even if you converted the .py script to an exe, the service still uses the python interpreter to run the service code itself. 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"

我猜另一台计算机上没有安装 python.如果您希望能够在不安装 python 的情况下在机器上运行该服务,您需要执行类似 这个,或者你也可以使用 cx_freeze

i'm guessing the other computer doesnt have python installed on it. 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 和 py2exe 的 Windows 服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆