Embed a .wav file in Python with pyinstaller Embed a .wav file in Python with pyinstaller tkinter tkinter

Embed a .wav file in Python with pyinstaller


It looks like you're using PyInstaller, not py2exe. As such this question is relevant.

I modified your mcve example to use a relative path to load my wav file.

import tkinterfrom pygame import mixerroot = tkinter.Tk()mixer.init()mixer.music.load("recy.wav")mixer.music.play()root.mainloop()

Then I included that data file in the pyinstaller command line to build the executable:

pyinstaller -w -F -i d_python.ico --add-data "recy.wav;." --log-level=WARN sound_test.py

From the documentation, --add-data needs src and a location, separated by ; on Windows and : everywhere else. Here I've just grabbed it from the local directory and similarly 'stored' it in the root directory of the distributed app.

This works for me, although the one-file (-F) option has a little bit of load overhead.