I am trying to take a Python file and convert it to an exe file with Pyinstaller. However, when I do so, I get an error saying:
Failed to execute python script.
Here is the pygame code:
import pygame
pygame.init()
clock = pygame.time.Clock()
screen = pygame.display.set_mode((400, 300))
pygame.display.set_caption("Auto Maze!")
myfont = pygame.font.SysFont("Arial", 13)
x, y = 168, 100
gameover = False
gameover2 = False
done = False
while not done:
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
if event.type == pygame.MOUSEBUTTONDOWN:
if gameover:
if button1.collidepoint(event.pos):
gameover = False
gameover2 = gameover
x, y = 168, 100
screen.fill((0, 0, 0))
"""try:
assert player.colliderect(wall1)
except AssertionError:
pass
except NameError:
pass
else:
death_screen = pygame.display.set_mode((400, 300))
button1 = pygame.draw.rect(death_screen, (0, 0, 255), (200, 200, 30, 30))
if donk:
break"""
if not gameover:
pressed = pygame.key.get_pressed()
if pressed[pygame.K_w]:
y -= 5
elif pressed[pygame.K_s]:
y += 5
elif pressed[pygame.K_a]:
x -= 5
elif pressed[pygame.K_d]:
x += 5
player = pygame.draw.rect(screen, (0, 255, 0), (x, y, 60, 60))
wall1 = pygame.draw.rect(screen, (255, 0, 0), (400, 0, -150, 300))
wall2 = pygame.draw.rect(screen, (255, 0, 0), (0, 0, 150, 300))
if player.colliderect(wall1):
gameover = True
elif player.colliderect(wall2):
gameover = True
else:
gameover = False
else:
button1 = pygame.draw.rect(screen, (0, 0, 255), (175, 100, 60, 30))
text = myfont.render("Try Again", False, (255, 0, 0))
screen.blit(text, (176, 107 ))
pygame.display.flip()
clock.tick(60)
quit()
And here is what I typed to convert the file:
pyinstaller --onefile -w "import pygame".py
Also, if there are any better alternatives to Pyinstaller, please do tell me. I've heard that Pyinstaller is not the best.
My OS is Windows 10.
You need to point pyinstaller to your.py file, not the first line of your.py file. For example if your file is called example.py, you need to write
pyinstaller --onefile -w example.py
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.