使用py2exe创建windows服务

2024-06-02 10:49:35 发布

您现在位置:Python中文网/ 问答频道 /正文

在 我需要以windows服务的形式运行python应用程序。 我可以使用命令,
python fservice.py install
python fservice.py start

现在,我想使用py2exe为我的应用程序创建exe。 我遵循了这个问题的代码:link

设置.py

from distutils.core import setup
import py2exe
import sys


if len(sys.argv) == 1:
    sys.argv.append("py2exe")
    sys.argv.append("-q")


class Target:
    def __init__(self, **kw):
        self.__dict__.update(kw)
        # for the versioninfo resources
        self.version = "0.0.1"
        self.company_name = "flotomate"
        self.copyright = "no copyright"
        self.name = "flotomate"

myservice = Target(
     # used for the versioninfo resource
     description = "flotomate",
     # what to build.  For a service, the module name (not the
     # filename) must be specified!
     modules = ["fservice"]
     )

setup(
     service = [myservice]
    )


服务.py

^{pr2}$

我正在使用命令创建exe,
python setup.py py2exe

但是,当我试图使用
fservice.exe --install

我得到这个错误

Traceback (most recent call last):
  File "boot_service.py", line 37, in <module>
AttributeError: 'module' object has no attribute 'Initialize


boot_service.py of py2exe
我使用的是python2.7.6和py2exe-0.6.9


Tags: thenamepyimport命令self应用程序service
1条回答
网友
1楼 · 发布于 2024-06-02 10:49:35

我也遇到了同样的问题。我不知道你是否找到了解决办法

在我的例子中,原因可能是servicemanager没有包含在编译的包中。python中安装的servicemanager库似乎存在冲突。在

为了解决这个问题,如果servicemanager未使用,我会卸载它,或者手动复制服务管理器.pyd到文件夹dist和服务mager.pyc至距离\图书馆.zip。如果在dist中有一个名为servicemanager的文件夹\图书馆.zip,删除它。在

如果您已经有了更好的解决方案,请与我们分享

相关问题 更多 >