【问题标题】:Program created by pyinstaller crashespyinstaller 创建的程序崩溃
【发布时间】:2019-02-16 13:16:52
【问题描述】:

如果我初始化 "pyinstaller main.py" 并将我的所有项目文件移动到 .exe 方向,它会统计。我可以在控制台中创建的菜单中做一些事情。

但是当我选择开始时,游戏就卡住了。我在 StackOverflow 上阅读了有关更改项目中声明字体的方式的信息,但我认为这还不够。整个游戏循环在一个名为game()的函数中,下面我将发布这个函数的代码。

谁能帮我解决这个问题?

我尝试使用pyinstaller 的 GUI 版本,但也没有用。

def play(self):
    self.reset()
    self.random_field()

    while self.game:
        self.screen.fill(self.background_color_play)
        direction = self.event_catcher()
        if direction:
            self.move(direction)
            if direction != "back":
                self.random_field()
                if self.score > self.best:
                    self.best = self.score

        for i in range(self.size*self.size):
            self.tiles[i].update_color()
            pygame.draw.rect(self.screen, self.tiles[i].color, [self.tiles[i].x1, self.tiles[i].y1,
                                                                self.tiles[i].x2, self.tiles[i].y2])
            if self.tiles[i].value:
                self.message_display(text=str(self.tiles[i].value), x=(2*self.tiles[i].x1+self.tiles[i].x2)/2,
                                     y=(2*self.tiles[i].y1+self.tiles[i].y2)/2, font_size=100,
                                     color=self.tiles[i].font_color, font="Clear Sans Bold")

        # UNDO
        if self.size_of_stack:
            self.message_display(text=Screen.req_word("undo", self.lang)+": {}".format(self.stack.size()//len(self.tiles)),
                                 x=20, y=(self.screen_height-self.screen_width+10)/2, font_size=30,
                                 color=(69, 69, 69), pos="left")
        else:
            self.message_display(text=Screen.req_word("undo", self.lang)+": 0",
                                 x=20, y=(self.screen_height-self.screen_width+10)/2, font_size=30,
                                 color=(69, 69, 69), pos="left")

        # SCORE
        self.message_display(text=Screen.req_word("score", self.lang)+": {}".format(self.score),
                             x=self.screen_width*0.5, y=(self.screen_height-self.screen_width+10)/2, font_size=30,
                             color=(69, 69, 69))

        # BEST SCORE
        self.message_display(text=Screen.req_word("best", self.lang)+": {}".format(self.best),
                             x=self.screen_width-20, y=(self.screen_height-self.screen_width+10)/2, font_size=30,
                             color=(69, 69, 69), pos="right")

        self.clock.tick(self.fps)
        pygame.display.update()

    self.main_menu()

我希望它不会在另一台没有安装 python 的计算机上崩溃。如果需要here 是完整代码

【问题讨论】:

  • 如果您从命令提示符启动可执行文件,您是否看到有用的回溯?我猜你的问题是加载资源。您使用的是什么.spec 文件?请考虑创建minimal reproducible example,以便其他人更容易帮助您。
  • 谢谢,一切都对我有用,问题出在字体上 :)

标签: python pygame pyinstaller


【解决方案1】:

@埃里克 我的 .spec 文件:

# -*- mode: python -*-

block_cipher = None


a = Analysis(['main.py'],
             pathex=['C:\\Projekty Pythona\\2048'],
             binaries=[],
             datas=[],
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,
          [],
          name='main',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          runtime_tmpdir=None,
          console=True )

今天我会尝试发现有问题的陈述

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-06-09
    • 1970-01-01
    • 1970-01-01
    • 2015-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多