Pygame - 未找到 "Mixer" 模块

Pygame - No "Mixer" module found

我想使用 pygame 在 raspberry pi 上播放音频文件。 当我执行这段代码时:

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

我得到一个错误:

  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)

我多次尝试使用不同的解决方案来解决此错误,但毫无进展。

这些是已安装的依赖项:

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

我猜我特别需要安装 libSDL2_mixer-2.0.so.0 但我尝试使用 pip 进行安装,但找不到任何具有该名称的包。 我正在为所有包使用虚拟环境,所以考虑到这一点,请告诉我如何尽快解决问题。

Python 版本:3.7.3

经过大量挖掘,我找到了适合我的解决方案。

只需执行命令:

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

仍然不明白它是如何工作的,因为我已经有了那些包。