简体   繁体   中英

convert python script to exe and run as windows service

I just created an python script that solve me a problem i need but i want to convert this script to exe file to run it in any windows machine without need of install python on it I have search of how could i convert the py to exe and run it and i have found that i could use script called py2exe the problem here that i want to convert my file to exe and run it as a windows service continuously on the my PC.

Here is the my script:

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

Could i have some help here

Python is an interpreted language, not a compiled one. As such, it needs its interpreter in order to be executed.

Bearing that in mind, you can use this: http://www.py2exe.org

More options given here: a good python to exe compiler?

or even better, in here: https://wiki.python.org/moin/DistributionUtilities

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM