Python Forum
Python 3.7, Windows 10, pyinstaller, winsound, no sound in executable
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python 3.7, Windows 10, pyinstaller, winsound, no sound in executable
#1
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.
Reply
#2
probably you want line #7 out of the except block
kmarien likes this post
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
whaaa, I searched for hours for a solution Wall . And I missed something this simple.

Thanks!
Reply
#4
(Nov-30-2020, 04:05 PM)kmarien Wrote: And I missed something this simple.
It happens to everyone :-)
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to compile a Python script for a Windows / Linux executable? netanelst 2 1,277 May-24-2022, 07:02 AM
Last Post: netanelst
  Pyinstaller 3 Python 2 mckymntl 0 1,206 Feb-07-2022, 06:28 AM
Last Post: mckymntl
  Python executable Script (Wrapper) Hwang 2 1,849 Jan-12-2022, 06:53 PM
Last Post: Hwang
  No module named '_cffi_backend' error with executable not with python script stephanh 2 5,557 Nov-25-2021, 06:52 AM
Last Post: stephanh
  Image to Sound Python Project ankitdixit 1 2,543 Jul-26-2021, 08:20 PM
Last Post: snippsat
  problem with pyinstaller to create an executable file atlass218 0 2,536 May-15-2021, 11:01 AM
Last Post: atlass218
  Real Time Audio Processing with Python Sound-Device not working Slartybartfast 2 3,882 Mar-14-2021, 07:20 PM
Last Post: Slartybartfast
  PyInstaller Executable Does Nothing pdihawk 18 12,662 Feb-22-2021, 04:43 PM
Last Post: pdihawk
  Play fixed frequency sound in python 3 jpezz 2 2,724 Feb-07-2021, 08:21 PM
Last Post: jpezz
  Make a Python program executable in Windows Pedroski55 1 2,067 Sep-26-2020, 12:34 AM
Last Post: bowlofred

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020