Search code examples
pythonmp3pyglet

How do I play .MP3 files in Python?


How do I play an MPs file in Python? I have tried

import os
os.system("start C:/thepathyouwant/file")

and every time I get the error: "couldn't locate file" I am working on a text based RPG, and I only want to add an MP3 file for music. I'm just starting out in Python, and don't know much about Pyglet. I attempted an install using the command line:

python setup.py install

In the "Run" window.

I also attempted to install pyglet.msi, but I recieved the error:

pyglet requires Python 2.4 or later. The installation will be aborted

running Python 2.7.9 running Windows 8

Thanks!


Solution

  • You can use startfile function in os module to play your file.Consider this example:

    import os
    os.startfile('C:/Users/Aakash/Desktop/songs/Anime.mp3')