【问题标题】:Undefined pygame error during loading music加载音乐期间未定义的 pygame 错误
【发布时间】:2023-03-19 02:23:01
【问题描述】:

我有以下简单的代码:

import pygame

pygame.init()
pygame.display.init()
pygame.display.set_mode((600, 600))

pygame.mixer.music.load('menu.mp3')
pygame.mixer.music.play(0)

is_running = True

while is_running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            is_running = False

当我在 cmd 中编译它时它工作正常。但是当我使用pyinstaller 将此脚本转换为 .exe 文件时,我遇到了未定义的问题。当我启动转换后的 .exe 文件时,我从 pygame 收到以下错误:

Traceback (most recent call last):
  File "test.py", line 7, in <module>
    pygame.mixer.music.load('menu.mp3')
pygame.error
[5208] Failed to execute script test

它发生了什么?

UPD:.exe 文件和menu.mp3 在同一目录中。

【问题讨论】:

    标签: python pygame pyinstaller


    【解决方案1】:

    你的 pyinstaller 命令是什么?您需要使用--add-data 选项来确定需要哪些文件。

    pyinstaller --onefile -w --add-data='menu.mp3;.' test.py
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-11-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-15
      • 2021-11-04
      相关资源
      最近更新 更多