Search code examples
pythonpygameraspberry-piraspberry-pi3

Pygame - No "Mixer" module found


I want to play audio file on my raspberry pi using pygame. when I execute this code:

import pygame
pygame.mixer.init()
pygame.mixer.music.load("/home/pi/Greetings/Welcome to the game.mp3")
pygame.mixer.music.play()

I get an error:

  File "try.py", line 14, in <module>
    pygame.mixer.init()
  File "/home/pi/visionbeyond_test/env/lib/python3.7/site-packages/pygame/__init__.py", line 59, in __getattr__
    raise NotImplementedError(missing_msg)
NotImplementedError: mixer module not available (ImportError: libSDL2_mixer-2.0.so.0: cannot open shared object file: No such file or directory)

I tried to solve this errors many times using different solutions but have reached absolutely nowhere.

These are the dependencies that are installed:

apt-cache search libsdl2
libsdl2-2.0-0 - Simple DirectMedia Layer
libsdl2-dev - Simple DirectMedia Layer development files
libsdl2-doc - Reference manual for libsdl2
libsdl2-gfx-1.0-0 - drawing and graphical effects extension for SDL2
libsdl2-gfx-dev - development files for SDL2_gfx
libsdl2-gfx-doc - documentation files for SDL2_gfx
libsdl2-image-2.0-0 - Image loading library for Simple DirectMedia Layer 2, libraries
libsdl2-image-dev - Image loading library for Simple DirectMedia Layer 2, development files
libsdl2-mixer-2.0-0 - Mixer library for Simple DirectMedia Layer 2, libraries
libsdl2-mixer-dev - Mixer library for Simple DirectMedia Layer 2, development files
libsdl2-net-2.0-0 - Network library for Simple DirectMedia Layer 2, libraries
libsdl2-net-dev - Network library for Simple DirectMedia Layer 2, development files
libsdl2-ttf-2.0-0 - TrueType Font library for Simple DirectMedia Layer 2, libraries
libsdl2-ttf-dev - TrueType Font library for Simple DirectMedia Layer 2, development files
libsdl2-2.0-0-dbgsym - debug symbols for libsdl2-2.0-0

I am guessing I specifically need to install libSDL2_mixer-2.0.so.0 but I tried using pip to install and it couldn't find any package with that name. I am using a virtual environment for all the packages so with that in mind please let me know how can I solve the problem as soon as possible.

Python version : 3.7.3


Solution

  • After a lot of digging I found the solution that worked for me.

    Just execute the command:

    apt-get install git curl libsdl2-mixer-2.0-0 libsdl2-image-2.0-0 libsdl2-2.0-0
    

    Still don't understand how it worked because I already had those packages.