使用 Python 和 py2exe 的 Windows 服务

发布于 2024-11-02 01:36:35 字数 520 浏览 3 评论 0原文

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

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

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

我玩了一下这个,然后回到我使用 py2exe 以及该服务的 exe 版本工作的机器。我删除了所有与 python 相关的内容,除了“dist”文件夹之外创建的所有 py2exe 内容,我能想到的所有内容都与该服务的 python 版本相关。 exe 版本仍然有效(尽管我删除了其他计算机上据称丢失的文件)。

尝试了很多不同的方法,但无法使 exe 版本正常工作。如果你们有任何想法,我将非常感激。

PS:我确实在目标计算机上安装了 C++ 运行时。没有它你就无法注册该服务,正如我所说,我可以注册它,但它不会运行。

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

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.

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.

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).

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: 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

北城孤痞 2024-11-09 01:36:35

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

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

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"

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

焚却相思 2024-11-09 01:36:35

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

有一些注释其中关于与 Windows 系统 dll 冲突的模块。他遇到了问题,因为他有一个名为 version 的模块,并且 import version 导致应用程序出错。

您可以尝试将 win32traceutil 导入为服务中的第一件事。这应该允许您运行 win32traceutil 控制台应用程序以显示服务的任何 stdout/stderr 输出。

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

There are some notes in there about modules conflicting with windows system dlls. He had a problem because he had a module called version and import version caused the app to error out.

You can try importing win32traceutil as the first thing in your service. This should allow you to run the win32traceutil console app to display any stdout/stderr output from the service.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文