将 python 脚本转换为 exe 并将 运行 转换为 windows 服务

convert python script to exe and run as windows service

我刚刚创建了一个 python 脚本来解决我需要的问题,但我想将此脚本转换为 exe 文件 运行 它在任何 windows 机器上都不需要在上面安装 python 我搜索了如何将 py 转换为 exe 并 运行 它,我发现我可以使用名为 py2exe 的脚本这里的问题是我想将我的文件转换为 exe 并 运行 它作为windows 在我的电脑上持续提供服务。

这是我的脚本:

import socket, sys, serial

HOST = ''   # Symbolic name, meaning all available interfaces
PORT = 8888 # Arbitrary non-privileged port

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print 'Socket created'

#Bind socket to local host and port
try:
    s.bind((HOST, PORT))
except socket.error as msg:
    print 'Bind failed. Error Code : ' + str(msg[0]) + ' Message ' + msg[1]
    sys.exit()

print 'Socket bind complete'

#Start listening on socket
s.listen(10)
print 'Socket now listening'

# try:

#now keep talking with the client
while 1:
    #wait to accept a connection - blocking call
    conn, addr = s.accept()
    # print('Connected with {}:{}'.format(addr[0], addr[1]))
    str = conn.recv(100)
    n_str = str[8:]
    last_c = n_str.find('%')
    last_str = n_str[:last_c]
    final_str = last_str.replace('+',' ')[:-3]
    print(final_str)
    try:
        pole = serial.Serial('COM4')
        pole.write('                                          \r\n')
        pole.write(final_str+'\r\n')
        pole.close()
    except:
        print(Exception.message)



s.close()

我可以帮忙吗

Python 是一种解释型语言,不是编译型语言。因此,它需要其解释器才能执行。

考虑到这一点,您可以使用:http://www.py2exe.org

此处提供更多选项:a good python to exe compiler?

甚至更好,在这里:https://wiki.python.org/moin/DistributionUtilities