0

I have this very simple test code:

from playsound import playsound

playsound('alarmsound.wav')

alarmsound.wav is a file in the same directory. when I run it in a terminal, it works fine. But when I run it in VSCode, it blows up with the following message:

Traceback (most recent call last):
  File "c:/Users/Luca/Desktop/Python/own/playaudio.py", line 3, in <module>
    playsound('alarmsound.wav')
  File "C:\Users\Luca\AppData\Local\Programs\Python\Python38-32\lib\site-packages\playsound.py", line 35, in _playsoundWin
    winCommand('open "' + sound + '" alias', alias)
  File "C:\Users\Luca\AppData\Local\Programs\Python\Python38-32\lib\site-packages\playsound.py", line 31, in winCommand
    raise PlaysoundException(exceptionMessage)
playsound.PlaysoundException:
    Error 275 for command:
        open "alarmsound.wav" alias playsound_0.7197283376226026
    Cannot find the specified file.  Make sure the path and filename are correct.

It used to work in vscode before, now suddenly it blows up. what could be wrong?

Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
lucafossen
  • 9
  • 1
  • 3
  • How are you running the code? Chances are your current working directory isn't what you think it is, so by using relative path it prevents Python from finding the `.wav` file. – Brett Cannon Jun 03 '20 at 20:53
  • wow, that solved it! I wasn't aware that i was running from the parent directory of the actual directory i was supposed to run. Thanks! – lucafossen Jun 04 '20 at 15:46

1 Answers1

0

Make sure you're actually running the file from the directory where your sound file is in.

In my case, it was running Python from the parent directory of the folder with the .wav file.

Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
lucafossen
  • 9
  • 1
  • 3