Python Forum

Full Version: Python 3.7, Windows 10, pyinstaller, winsound, no sound in executable
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm trying to make a christmas card in python. If a run the program with python it runs fine.

but after:

pyinstaller cc.py -w -y --clean --onefile --add-data "music;music"
The exe is created succesfully, but there is no sound at all. I can see it takes time to extract the music. Though, the program continues without music.

On linux everything works when compiling the program. Only change there is I don't use winsound.

Partial python code:

# resource_path is the relative path to the resource file
def resource_path(relative_path):
    try:
        base_path = sys._MEIPASS
    except Exception:
        base_path = os.path.abspath(".")
        return os.path.join(base_path, relative_path)
    
# Play background music
bgm = resource_path("music\letitsnow.wav")
volume = 1.0
winsound.PlaySound(bgm, winsound.SND_FILENAME|winsound.SND_ASYNC)
time.sleep(1)
Any suggestions? I just started learning python. And the windows thing is not really my thing but I need to compile the christmas card for windows also.
probably you want line #7 out of the except block
whaaa, I searched for hours for a solution Wall . And I missed something this simple.

Thanks!
(Nov-30-2020, 04:05 PM)kmarien Wrote: [ -> ]And I missed something this simple.
It happens to everyone :-)