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
  Image to Sound Python Project ankitdixit 1 160 Jul-26-2021, 08:20 PM
Last Post: snippsat
  problem with pyinstaller to create an executable file atlass218 0 411 May-15-2021, 11:01 AM
Last Post: atlass218
  Real Time Audio Processing with Python Sound-Device not working Slartybartfast 2 766 Mar-14-2021, 07:20 PM
Last Post: Slartybartfast
  PyInstaller Executable Does Nothing pdihawk 18 1,851 Feb-22-2021, 04:43 PM
Last Post: pdihawk
  Play fixed frequency sound in python 3 jpezz 2 468 Feb-07-2021, 08:21 PM
Last Post: jpezz
  Make a Python program executable in Windows Pedroski55 1 579 Sep-26-2020, 12:34 AM
Last Post: bowlofred
  Executable looks like virus to windows samuelbachorik 4 1,087 Apr-27-2020, 02:46 PM
Last Post: samuelbachorik
  How to keep a loop containing a web import working in python executable? coder1384 3 1,093 Feb-22-2020, 06:49 PM
Last Post: snippsat
  Error while trying to see Python version with "sys.executable" karkas 5 1,857 Feb-09-2020, 01:55 AM
Last Post: karkas
  Cannot Change Python script to exe using Pyinstaller omar_mohsen 3 943 Dec-19-2019, 01:05 PM
Last Post: buran

Forum Jump:

User Panel Messages

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