简体   繁体   中英

Pyinstaller : Cannot include .mp3 files

I'm trying to create a stand-alone python application (Tic-Tac-Toe) using pyinstaller . I wrote the following commands in the command prompt:

pyinstaller -w --onedir x_and_o.py

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

The.mp3 files are saved in the folder "Sound". Everything was executed 'Successfully' but I'm still getting the following error:

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.

Here's a snippet from my code:

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

I've tried looking up for solutions online but couldn't find any solution to my problem.

I'm using Windows 10 and coding in VS code.

To solve the following error:

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

I simply needed to download this file and move it to my application folder. You can read about libmpg123 here

I solved this by editing init_library in the library file mpg123.py. By hardwriting the location of the.dll into this method (if you need the dll you can acquire a compiled binary from the mpg123 site), and then using the pyinstaller flag to include the.dll, it will be correctly packaged into the exe.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM