-1

I'm trying to use pyinstaller to create an executable for my project, but when it hits the "playsound" function, outputs the error below. This only happens with the executable and not the regular code.

Error 263 for command:
        open success.mp3
    The specified device is not open or is not recognized by MCI.

    Error 263 for command:
        close success.mp3
    The specified device is not open or is not recognized by MCI.
Failed to close the file: success.mp3
Exception in Tkinter callback
Traceback (most recent call last):
  File "tkinter\__init__.py", line 1892, in __call__
  File "Main.py", line 137, in <lambda>
  File "Main.py", line 122, in loop
  File "Main.py", line 109, in loopOver
  File "playsound.py", line 72, in _playsoundWin
  File "playsound.py", line 64, in winCommand
playsound.PlaysoundException:
    Error 263 for command:
        open success.mp3
    The specified device is not open or is not recognized by MCI.

This is the code running playsound:

from playsound import playsound
   playsound('success.mp3', False)

the file structure looks like this: enter image description here

and this is the command i'm using to compile:

pyinstaller main.spec which has all modifications I need inside the .spec file

I'll be honest i'm completely stumped by this so I was hoping someone may have run into something similar in the past and can help me out? Thanks in advance!

Tom154ce
  • 37
  • 2
  • @Alexander that was just a snippet to show the issue line. But i'm unsure how to provide a minimal reproducible example when it only occurs when compiling my entire project. This is why I asked if someone might've ran into the issue before :( – Tom154ce Jan 21 '23 at 03:11
  • Well this doesn't play a sound for me once i've used pyinstaller, so if you're able to help me understand this, it may help my issue aha https://pastebin.com/Kju5qTYD – Tom154ce Jan 21 '23 at 03:27

1 Answers1

-1

To fix this, I implemented this code that I found from here to get my audio to load with pyinstaller:

def resource_path(relative_path):
if hasattr(sys, '_MEIPASS'):
    return os.path.join(sys._MEIPASS, relative_path)
return os.path.join(os.path.abspath("."), relative_path)

playsound(resource_path("success.mp3"), False)
Tom154ce
  • 37
  • 2