播放音频在 Repl.IT 上不起作用,因为代码在服务器上运行,该服务器与您计算机的扬声器没有连接。这是输出,当我重现您的错误时:pygame 1.9.6Hello from the pygame community. https://www.pygame.org/contribute.htmlALSA lib confmisc.c:767:(parse_card) cannot find card '0' <--- ALSA can not find the cardALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directoryALSA lib confmisc.c:392:(snd_func_concat) error evaluating stringsALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directoryALSA lib confmisc.c:1246:(snd_func_refer) error evaluating nameALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directoryALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directoryALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM defaultALSA lib confmisc.c:767:(parse_card) cannot find card '0' <--- ALSA can still not find itALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directoryALSA lib confmisc.c:392:(snd_func_concat) error evaluating stringsALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directoryALSA lib confmisc.c:1246:(snd_func_refer) error evaluating nameALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directoryALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directoryALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM defaultTraceback (most recent call last): File "main.py", line 3, in <module> pygame.mixer.init()pygame.error: No available audio deviceexit status 1请参阅https://repl.it/talk/ask/Pygame-Audio-Issues/12147。
我假设您在 Linux 环境中工作,因此,我建议您安装以下必备库:-libSDL-1_2libSDL_devellibSDL_image-1_2libSDL_mixer-1_2libSDL_ttf-2在 ubuntu 中,您可以使用以下行sudo apt-get install libsdl1.2-dev libsdl-image1.2 libsdl-mixer1.2 libsdl-ttf2.0