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

时间:2016-02-07 12:33:38

标签: python windows python-2.7 openerp py2exe

我刚刚创建了一个python脚本,解决了我需要的问题,但我想将此脚本转换为exe文件,以便在任何Windows机器上运行它而无需安装python就可以了 我搜索了如何将py转换为exe并运行它,我发现我可以使用名为py2exe的脚本这里的问题,我想将我的文件转换为exe并在我的PC上连续运行它作为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()

我可以在这里得到一些帮助

1 个答案:

答案 0 :(得分:3)

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

请注意,您可以使用:http://www.py2exe.org

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

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