簡體   English   中英

成功執行exe后無法執行腳本錯誤

[英]Failed to execute script error after successful execution exe

我正在嘗試使用 pyinstaller 為我的 pygame 游戲創建一個 exe 文件。 我使用的命令是pyinstaller --noconsole 2d_minecraft.py 它成功創建了 dist 文件夾。

成功執行創建的 exe 文件出現此錯誤。 如果沒有--noconsole選項,這不會發生。

代碼:

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

在此處輸入圖像描述

我想通了我需要做的就是將exit()更改為sys.exit() (並添加import sys )。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM