I am trying to create an exe file for my pygame game with pyinstaller. The command I am using is pyinstaller --noconsole 2d_minecraft.py
. It creates the dist folder successfully.
I am getting this error after a successful execution of the exe file created. This does not happen without the --noconsole
option.
code:
import pymc
import pygame
import random
import perlin_noise
pygame.init()
WIN = pygame.display.set_mode((960, 640))
WIN_WIDTH, WIN_HEIGHT = WIN.get_width(), WIN.get_height()
WORLD_WIDTH, WORLD_HEIGHT = 64, 64
FPS = 60
pymc.set_title("2d Minecraft")
class objects():
to_draw = []
run = True
cam_y = (WORLD_HEIGHT/2)*64
cam_x = (WORLD_WIDTH/2)*64
block_textures = {
[...]
}
class tile():
[...]
def handle_keys():
[...]
def generate_world():
[...]
def main():
clock = pygame.time.Clock()
tiles = generate_world()
while objects.run:
clock.tick(FPS)
objects.to_draw = []
for event in pygame.event.get():
if event.type == pygame.QUIT:
objects.run = False
pygame.quit()
exit()
for x in range(0, WORLD_WIDTH):
for y in range(0, WORLD_HEIGHT):
objects.to_draw.append(tiles[x][y])
handle_keys()
pymc.draw_window(WIN, objects.to_draw, fill=(0, 150, 255))
main()
main()
I figured it out!! All I needed to do was change exit()
to sys.exit()
(and add import sys
as well).