REPL.IT:Python Pygame:你如何修复“pygame.error:

我正在尝试将声音与我的 Python Pygame 游戏一起使用,它给我带来了这个错误:


Traceback (most recent call last):

  File "main.py", line 5, in <module>

    pygame.mixer.init()

pygame.error: No available audio device

我将如何解决这个问题?


*在此先感谢您的帮助!


慕仙森
浏览 436回答 2
2回答

慕工程0101907

播放音频在 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):&nbsp; &nbsp;File "main.py", line 3, in <module>&nbsp; &nbsp; &nbsp; pygame.mixer.init()pygame.error: No available audio deviceexit status 1请参阅https://repl.it/talk/ask/Pygame-Audio-Issues/12147。

RISEBY

我假设您在 Linux 环境中工作,因此,我建议您安装以下必备库:-libSDL-1_2libSDL_devellibSDL_image-1_2libSDL_mixer-1_2libSDL_ttf-2在 ubuntu 中,您可以使用以下行sudo&nbsp;apt-get&nbsp;install&nbsp;libsdl1.2-dev&nbsp;libsdl-image1.2&nbsp;libsdl-mixer1.2&nbsp;libsdl-ttf2.0
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python