我刚用PyInstaller编译了一个文件,当我运行它时,它说:
Error: Program stoped working
我的program.py(我知道它很大,用葡萄牙语评论):
# -*- coding: utf-8 -*-
from Crypto.Cipher import AES
import base64
import os
import pygame, sys, easygui, time, datetime
from socket import *
coinse=0
def resource_path(relative):
return os.path.join(
os.environ.get(
"_MEIPASS2",
os.path.abspath(".")
),
relative
)
def encryption(data):
BLOCK_SIZE = 32
PADDING = '{'
pad = lambda s: s + (BLOCK_SIZE - len(s) % BLOCK_SIZE) * PADDING
EncodeAES = lambda c, s: base64.b64encode(c.encrypt(pad(s)))
secret = "g5774b1111fdd3ty"
cipher = AES.new(secret)
encoded = EncodeAES(cipher, str(data))
return encoded
def decryption(data):
BLOCK_SIZE = 32
PADDING = '{'
secret = "g5774b1111fdd3ty"
DecodeAES = lambda c, e: c.decrypt(base64.b64decode(e)).rstrip(PADDING)
cipher = AES.new(secret)
decoded = DecodeAES(cipher, data)
return decoded
def asserver():
global coinse
address = ('0.0.0.0', 7000)
server = socket(AF_INET, SOCK_STREAM) #SERVER SOCKET
server.bind(address) #SERVER SOCKET
pos=[10,10]
pos2=[10, 10]
journey=[10,10]
white=(255,255,255)
red=(170, 20, 0)
black=(0, 0, 0)
pygame.init()
screen=pygame.display.set_mode([700,500])
screen.fill(white)
pygame.display.flip()
pygame.display.set_caption("Multiplayer Game")
health=100 # Vida
health2=100 #Vida do oponente
cool=datetime.datetime.now() # Variável usada para o cool-down
cool2=datetime.datetime.now()
cool3=datetime.datetime.now()
cool4=datetime.datetime.now()
bef=datetime.datetime.now() # o mesmo que cool(2)(3)(4)
bef2=datetime.datetime.now()
bef3=datetime.datetime.now()
bef4=datetime.datetime.now()
draw=False #Variável de valor True enquanto o player1 usa um/uma poder/abilidade
draw2=False
draw3=False
draw4=False
toatk=False #to: variáveis que convertem para draw(2)(3)(4)
todef=False
toinv=False
tosh=False
atk=False #Variáveis de valor True enquanto o player2 usa um/uma poder/abilidade
deff=False
inv=False
sh=False
loop2=True
loop=True
towin=False
won=False
data=None
font=pygame.font.Font(None, 25)
font2=pygame.font.Font(None, 35)
screen.fill([255,255,255])
screen.blit(font2.render("Press ENTER to start a game!", 1, (0,0,0)), [145, 230])
pygame.display.flip()
while loop2==True:
for event in pygame.event.get():
if event.type==pygame.QUIT:
sys.exit()
elif event.type==pygame.KEYDOWN:
if event.key==pygame.K_RETURN:
loop2=False
break
server.listen(1)
server_socket, x = server.accept()
while loop==True:
print data
if won==" True":
screen.fill(white)
coinse=str(int(3000/health2))
if int(coinse)>60:
coinse="60"
easygui.msgbox("YOU LOST!\nYour enemy had "+str(int(health2))+" health left!\nYou earned "+coinse+"!")
break
if health2==0:
screen.fill(white)
coinse=str(int(health*2+50))
easygui.msgbox("YOU WON!\nYou had "+str(int(health))+" health left!\nYou earned "+coinse+" coins!")
towin=True
data=server_socket.recv(2048)
sending=str([pos[0], pos[1], toatk, int(health), todef, toinv, tosh, towin])
server_socket.send(sending)
data=data.strip("[").strip("]").split(",")
data[0]=int(data[0])
data[1]=int(data[1])
data[3]=int(data[3])
sh=data[6]
won=data[7]
inv=data[5]
pos2=[data[0], data[1]]
atk=data[2]
deff=data[4]
health2=data[3]
screen.fill(white)
if towin==True:
screen.fill(white)
pygame.display.flip()
break
if sh==" True":
black=(0,20,220)
else:
black=(0,0,0)
if deff==" True" and inv==" False":
black=(0,200,0)
elif deff==" False":
black=(0,0,0)
if atk==" True" and inv==" False":
bef2=datetime.datetime.now()
pygame.draw.circle(screen, [255,0,0], pos2, 48)
pygame.draw.circle(screen, [255,255,255], pos2, 45)
if draw2==True:
now=datetime.datetime.now()
if (now-bef2).seconds<5:
red=(0,200,0)
if not health>100:
health=health+0.01
else:
red=(170, 20, 0)
draw2=False
todef=False
if draw==True:
now=datetime.datetime.now()
if (now-bef).seconds<3:
pygame.draw.circle(screen, [255,0,0], pos, 48)
pygame.draw.circle(screen, [255,255,255], pos, 45)
else:
draw=False
toatk=False
if draw3==True:
now=datetime.datetime.now()
if (now-bef3).seconds<4:
pygame.draw.circle(screen, red, pos, 10)
pygame.draw.circle(screen, white, pos, 9)
else:
draw3=False
toinv=False
else:
pygame.draw.circle(screen, red, pos, 10)
if draw4==True:
now=datetime.datetime.now()
if (now-bef4).seconds<2:
red=(0,20,220)
else:
red=(170,20,0)
draw4=False
tosh=False
if inv==" True":
pass
else:
pygame.draw.circle(screen, black, pos2, 10)
screen.blit(font.render("Your Health: "+str(int(health)), 1, (0,0,0)), [10,10])
screen.blit(font.render("Enemy Health: "+str(health2), 1, (0,0,0)), [300, 10])
if (datetime.datetime.now()-cool).seconds>10:
screen.blit(font.render("Attack", 1, (0,255,0)), [300, 50])
else:
screen.blit(font.render("Attack", 1, (255,0,0)), [300, 50])
if (datetime.datetime.now()-cool2).seconds>15:
screen.blit(font.render("Heal", 1, (0,255,0)), [400, 50])
else:
screen.blit(font.render("Heal", 1, (255,0,0)), [400, 50])
if (datetime.datetime.now()-cool3).seconds>25:
screen.blit(font.render("Invisibility", 1, (0,255,0)), [470, 50])
else:
screen.blit(font.render("Invisibility", 1, (255,0,0)), [470, 50])
if (datetime.datetime.now()-cool4).seconds>15:
screen.blit(font.render("Shield", 1, (0,255,0)), [600, 50])
else:
screen.blit(font.render("Shield", 1, (255,0,0)), [600, 50])
pygame.display.flip()
if journey[0]> pos[0] and journey[1] > pos[1]:
pos[0]=pos[0]+1
pos[1]=pos[1]+1
elif journey[0]< pos[0] and journey[1] < pos[1]:
pos[0]=pos[0]-1
pos[1]=pos[1]-1
elif journey[0]> pos[0] and journey[1] < pos[1]:
pos[0]=pos[0]+1
pos[1]=pos[1]-1
elif journey[0]< pos[0] and journey[1] > pos[1]:
pos[0]=pos[0]-1
pos[1]=pos[1]+1
elif journey[0]> pos[0]:
pos[0]=pos[0]+1
elif journey[0]< pos[0]:
pos[0]=pos[0]-1
elif journey[1]> pos[1]:
pos[1]=pos[1]+1
elif journey[1]< pos[1]:
pos[1]=pos[1]-1
if pos[0]-pos2[0] < 1 and pos[0]-pos2[0] > -51 and pos[1]-pos2[1] < 1 and pos[1]-pos2[1] > -51 and atk==" True" and tosh==False:
health=health-0.04
if pos[0]-pos2[0] < 51 and pos[0]-pos2[0] > 0 and pos[1]-pos2[1] < 51 and pos[1]-pos2[1] > 0 and atk==" True" and tosh==False:
health=health-0.04
if pos[0]-pos2[0] < 51 and pos[0]-pos2[0] > 0 and pos[1]-pos2[1] < 1 and pos[1]-pos2[1] > -51 and atk==" True" and tosh==False:
health=health-0.04
if pos[0]-pos2[0] < 1 and pos[0]-pos2[0] > -51 and pos[1]-pos2[1] < 51 and pos[1]-pos2[1] > 0 and atk==" True" and tosh==False:
health=health-0.04
for event in pygame.event.get():
if event.type==pygame.QUIT:
pygame.quit()
loop=False
elif event.type==pygame.MOUSEBUTTONDOWN:
if event.button==1:
journey=event.pos
elif event.type==pygame.KEYDOWN:
if event.key==pygame.K_q:
if (datetime.datetime.now()-cool).seconds>10:
toatk=True
draw=True
bef=datetime.datetime.now()
cool=datetime.datetime.now()
else:
pass
if event.key==pygame.K_w:
if (datetime.datetime.now()-cool2).seconds>15:
todef=True
draw2=True
bef2=datetime.datetime.now()
cool2=datetime.datetime.now()
else:
pass
if event.key==pygame.K_e:
if (datetime.datetime.now()-cool3).seconds>25:
toinv=True
draw3=True
bef3=datetime.datetime.now()
cool3=datetime.datetime.now()
else:
pass
if event.key==pygame.K_r:
if (datetime.datetime.now()-cool4).seconds>15:
tosh=True
draw4=True
bef4=datetime.datetime.now()
cool4=datetime.datetime.now()
else:
pass
def asclient():
global coinse
pos=[10,10] #posição
pos2=[10,10] #posição do inimigo
journey=[10,10] #posição final
white=(255,255,255) #cor do fundo
red=(170, 20, 0) # cor do player1
black=(0, 0, 0) #cor do player2
pygame.init()
screen=pygame.display.set_mode([700,500])
screen.fill(white)
pygame.display.flip()
pygame.display.set_caption("Multiplayer Game")
#CLIENT SOCKET
client_socket = socket(AF_INET, SOCK_STREAM)
#CLIENT SOCKET
health=100 # Vida
health2=100 #Vida do oponente
cool=datetime.datetime.now() # Variável usada para o cool-down
cool2=datetime.datetime.now()
cool3=datetime.datetime.now()
cool4=datetime.datetime.now()
bef=datetime.datetime.now() # o mesmo que cool(2)(3)(4)
bef2=datetime.datetime.now()
bef3=datetime.datetime.now()
bef4=datetime.datetime.now()
draw=False #Variável de valor True enquanto o player1 usa um/uma poder/abilidade
draw2=False
draw3=False
draw4=False
toatk=False #to: variáveis que convertem para draw(2)(3)(4)
todef=False
toinv=False
tosh=False
atk=False #Variáveis de valor True enquanto o player2 usa um/uma poder/abilidade
deff=False
inv=False
sh=False
loop2=True
loop=True
towin=False
won=False
data=None
font=pygame.font.Font(None, 25) #Tipo de Letra pequeno
font2=pygame.font.Font(None, 35) #Tipo de Letra grande
screen.fill([255,255,255])
screen.blit(font2.render("Press ENTER to join a game!", 1, (0,0,0)), [150, 230])
pygame.display.flip()
while loop2==True:
for event in pygame.event.get():
if event.type==pygame.QUIT:
sys.exit()
elif event.type==pygame.KEYDOWN:
if event.key==pygame.K_RETURN:
address=easygui.multenterbox("Info:", fields=("IP:", "PORT:"))
address[1]=int(address[1])
address=tuple(address)
loop2=False
break
client_socket.connect(address)
while loop==True:
if won==" True":
screen.fill(white)
coinse=str(int(3000/health2))
if int(coinse)>60:
coinse="60"
easygui.msgbox("YOU LOST!\nYour enemy had "+str(int(health2))+" health left!\nYou earned "+coinse+"!")
break
if health2==0:
screen.fill(white)
coinse=str(int(health*2+50))
easygui.msgbox("YOU WON!\nYou had "+str(int(health))+" health left!\nYou earned "+coinse+" coins!")
towin=True
sending=str([pos[0], pos[1], toatk, int(health), todef, toinv, tosh, towin])
client_socket.send(sending)
data=client_socket.recv(2048)
data=data.strip("[").strip("]").split(",")
data[0]=int(data[0])
data[1]=int(data[1])
data[3]=int(data[3])
sh=data[6]
deff=data[4]
pos2=[data[0], data[1]]
atk=data[2]
inv=data[5]
won=data[7]
health2=data[3]
screen.fill(white)
if towin==True:
screen.fill(white)
pygame.display.flip()
break
if sh==" True":
black=(0,20,220)
if atk==" True" and inv==" False":
pygame.draw.circle(screen, [255,0,0], pos2, 48)
pygame.draw.circle(screen, [255,255,255], pos2, 45)
if draw==True:
now=datetime.datetime.now()
if (now-bef).seconds<3:
pygame.draw.circle(screen, [255,0,0], pos, 48)
pygame.draw.circle(screen, [255,255,255], pos, 45)
else:
draw=False
toatk=False
if deff==" True" and inv==" False":
black=(0,200,0)
else:
black=(0,0,0)
if draw2==True:
now=datetime.datetime.now()
if (now-bef2).seconds<5:
red=(0,200,0)
if not health>100:
health=health+0.01
else:
red=(170, 20, 0)
draw2=False
todef=False
if draw3==True:
now=datetime.datetime.now()
if (now-bef3).seconds<4:
pygame.draw.circle(screen, red, pos, 10)
pygame.draw.circle(screen, white, pos, 9)
else:
draw3=False
toinv=False
else:
pygame.draw.circle(screen, red, pos, 10)
if draw4==True:
now=datetime.datetime.now()
if (now-bef4).seconds<2:
red=(0,20,220)
else:
red=(170,20,0)
draw4=False
tosh=False
if inv==" True":
pass
else:
pygame.draw.circle(screen, black, pos2, 10)
screen.blit(font.render("Your Health: "+str(int(health)), 1, (0,0,0)), [10,10])
screen.blit(font.render("Enemy Health: "+str(health2), 1, (0,0,0)), [300, 10])
if (datetime.datetime.now()-cool).seconds>10:
screen.blit(font.render("Attack", 1, (0,255,0)), [300, 50])
else:
screen.blit(font.render("Attack", 1, (255,0,0)), [300, 50])
if (datetime.datetime.now()-cool2).seconds>15:
screen.blit(font.render("Heal", 1, (0,255,0)), [400, 50])
else:
screen.blit(font.render("Heal", 1, (255,0,0)), [400, 50])
if (datetime.datetime.now()-cool3).seconds>25:
screen.blit(font.render("Invisibility", 1, (0,255,0)), [470, 50])
else:
screen.blit(font.render("Invisibility", 1, (255,0,0)), [470, 50])
if (datetime.datetime.now()-cool4).seconds>15:
screen.blit(font.render("Shield", 1, (0,255,0)), [600, 50])
else:
screen.blit(font.render("Shield", 1, (255,0,0)), [600, 50])
pygame.display.flip()
if journey[0]> pos[0] and journey[1] > pos[1]:
pos[0]=pos[0]+1
pos[1]=pos[1]+1
elif journey[0]< pos[0] and journey[1] < pos[1]:
pos[0]=pos[0]-1
pos[1]=pos[1]-1
elif journey[0]> pos[0] and journey[1] < pos[1]:
pos[0]=pos[0]+1
pos[1]=pos[1]-1
elif journey[0]< pos[0] and journey[1] > pos[1]:
pos[0]=pos[0]-1
pos[1]=pos[1]+1
elif journey[0]> pos[0]:
pos[0]=pos[0]+1
elif journey[0]< pos[0]:
pos[0]=pos[0]-1
elif journey[1]> pos[1]:
pos[1]=pos[1]+1
elif journey[1]< pos[1]:
pos[1]=pos[1]-1
if pos[0]-pos2[0] < 1 and pos[0]-pos2[0] > -51 and pos[1]-pos2[1] < 1 and pos[1]-pos2[1] > -51 and atk==" True" and tosh==False:
health=health-0.04
if pos[0]-pos2[0] < 51 and pos[0]-pos2[0] > 0 and pos[1]-pos2[1] < 51 and pos[1]-pos2[1] > 0 and atk==" True" and tosh==False:
health=health-0.04
if pos[0]-pos2[0] < 51 and pos[0]-pos2[0] > 0 and pos[1]-pos2[1] < 1 and pos[1]-pos2[1] > -51 and atk==" True" and tosh==False:
health=health-0.04
if pos[0]-pos2[0] < 1 and pos[0]-pos2[0] > -51 and pos[1]-pos2[1] < 51 and pos[1]-pos2[1] > 0 and atk==" True" and tosh==False:
health=health-0.04
for event in pygame.event.get():
if event.type==pygame.QUIT:
pygame.quit()
loop=False
elif event.type==pygame.MOUSEBUTTONDOWN:
if event.button==1:
journey=event.pos
elif event.type==pygame.KEYDOWN:
if event.key==pygame.K_q:
if (datetime.datetime.now()-cool).seconds>10:
toatk=True
draw=True
bef=datetime.datetime.now()
cool=datetime.datetime.now()
else:
pass
if event.key==pygame.K_w:
if (datetime.datetime.now()-cool2).seconds>15:
todef=True
draw2=True
bef2=datetime.datetime.now()
cool2=datetime.datetime.now()
else:
pass
if event.key==pygame.K_e:
if (datetime.datetime.now()-cool3).seconds>25:
toinv=True
draw3=True
bef3=datetime.datetime.now()
cool3=datetime.datetime.now()
else:
pass
if event.key==pygame.K_r:
if (datetime.datetime.now()-cool4).seconds>15:
tosh=True
draw4=True
bef4=datetime.datetime.now()
cool4=datetime.datetime.now()
else:
pass
bypass=False
try:
s=open(resource_path("profile.data"), "r")
eprofile=s.readline()
s.close()
profile=decryption(eprofile).strip("[").strip("]").split(",")
coins=profile[0]
name=profile[1].strip(" ")
password=profile[2].strip(" ")
except:
bypass=True
coins=0
name=None
password=None
login=["", "", ""]
if not bypass==True:
login=easygui.multpasswordbox("Login:", fields=["Name:", "Password:"])
if not bypass==True and name==login[0] and password==login[1]:
pygame.init()
screen=pygame.display.set_mode([700,500])
pygame.display.set_caption("Multiplayer Game")
screen.fill([255,255,255])
pygame.display.flip()
fontt=pygame.font.Font(None, 30)
screen.blit(fontt.render("Start a game", 1, (0,0,0)), [20, 55])
screen.blit(fontt.render("Join a game", 1, (0,0,0)), [20, 95])
screen.blit(fontt.render(str(coins)+" coins", 1, (255,201,14)), [570, 460])
pygame.display.flip()
while True:
for event in pygame.event.get():
if event.type==pygame.QUIT:
sys.exit()
elif event.type==pygame.MOUSEBUTTONDOWN:
if event.pos[0] > 14 and event.pos[0] < 143 and event.pos[1] > 51 and event.pos[1] < 71:
asserver()
e=encryption(int(coinse)+coins)
s=open("profile.data", "w")
s.write(e)
s.close()
coinse=0
if event.pos[0] > 14 and event.pos[0] < 143 and event.pos[1] > 92 and event.pos[1] < 108:
asclient()
e=encryption(int(coinse)+coins)
s=open("profile.data", "w")
s.write(e)
s.close()
coinse=0
elif bypass==True:
pygame.init()
screen=pygame.display.set_mode([700,500])
pygame.display.set_caption("Multiplayer Game")
screen.fill([255,255,255])
pygame.display.flip()
fontt=pygame.font.Font(None, 30)
screen.blit(fontt.render("Start a game", 1, (0,0,0)), [20, 55])
screen.blit(fontt.render("Join a game", 1, (0,0,0)), [20, 95])
screen.blit(fontt.render(str(coins)+" coins", 1, (255,201,14)), [570, 460])
pygame.display.flip()
while True:
for event in pygame.event.get():
if event.type==pygame.QUIT:
sys.exit()
elif event.type==pygame.MOUSEBUTTONDOWN:
if event.pos[0] > 14 and event.pos[0] < 143 and event.pos[1] > 51 and event.pos[1] < 71:
asserver()
e=encryption(int(coinse)+coins)
s=open("profile.data", "w")
s.write(e)
s.close()
coinse=0
if event.pos[0] > 14 and event.pos[0] < 143 and event.pos[1] > 92 and event.pos[1] < 108:
asclient()
e=encryption(int(coinse)+coins)
s=open("profile.data", "w")
s.write(e)
s.close()
coinse=0
else:
easygui.msgbox("LOGIN FAILED!")
有人可以告诉我该怎么做吗?
要编译,我这样做:
pyinstaller.py program.py --noconsole
答案 0 :(得分:3)
这部分似乎没有错误。很难说,因为你没有包括完整的程序。
如果你使用linux或Mac,你可以在终端上运行你的程序
python <program_name.py>
如果没有,你可以制作可执行程序 点击此链接
http://askubuntu.com/questions/244378/run-python-in-terminal
答案 1 :(得分:2)
发现此错误
File "test.py", line 58
SyntaxError: Non-ASCII character '\xc3' in file test.py on line 58, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details