Pyinstaller:无法包含 .mp3 文件

Pyinstaller : Cannot include .mp3 files

我正在尝试使用 pyinstaller 创建一个独立的 python 应用程序 (Tic-Tac-Toe)。我在命令提示符下写了以下命令:

pyinstaller -w --onedir x_and_o.py

pyinstaller --add-data "Sound;snds" x_and_o.py

.mp3 文件保存在“声音”文件夹中。一切都已执行 'Successfully' 但我仍然收到以下错误:

pygame 1.9.6
Hello from the pygame community. 
https://www.pygame.org/contribute.html
Exception in Tkinter callback
Traceback (most recent call last):
   File "tkinter\__init__.py", line 1883, in __call__
   File "x_and_o.py", line 216, in <lambda>
   File "x_and_o.py", line 30, in changeText
   File "x_and_o.py", line 182, in pop
 pygame.error: Failed loading libmpg123.dll: The specified 
 module could not be found.

这是我的代码片段:

pygame.mixer.init()

def pop_sound():
pygame.mixer.music.load(r"C:\Users\Dipesh\OneDrive\Desktop\Visual Studio Code\Tic-Tac-Toe Project\Sound\pop.mp3") # r means 'raw string'
pygame.mixer.music.play()

def Air_horn():
pygame.mixer.music.load(r"C:\Users\Dipesh\OneDrive\Desktop\Visual Studio Code\Tic-Tac-Toe Project\Sound\Air horn.mp3") # r means 'raw string'
pygame.mixer.music.play()

def game_over_sound():
pygame.mixer.music.load(r"C:\Users\Dipesh\OneDrive\Desktop\Visual Studio Code\Tic-Tac-Toe 
Project\Sound\gameOver.mp3")
pygame.mixer.music.play()

我试过在线查找解决方案,但找不到解决我的问题的方法。

我正在使用 Windows 10 并在 VS 代码中编码。

解决以下错误:

pygame.error: Failed loading libmpg123.dll: The specified 
module could not be found.

我只需要 download this file 并将其移动到我的应用程序文件夹中。 您可以阅读有关 libmpg123 here

我通过编辑库文件 mpg123.py 中的 init_library 解决了这个问题。通过将 .dll 的位置硬写到此方法中(如果需要 dll,可以从 mpg123 站点获取已编译的二进制文件),然后使用 pyinstaller 标志包含 .dll,它将正确打包到 exe 中。