当我尝试运行使用pygame的,我得到一个缓慢的“启动”程序(INIT)(4-5s),并从ALSA此错误。固定ALSA是不是我的目标,我想知道为什么是如果我有我的代码没有使用音频被初始化。
$ python slides.py
aaaaaaaaaa
ALSA lib confmisc.c:768:(parse_card) cannot find card '0'
ALSA lib conf.c:4259:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
ALSA lib conf.c:4259:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
ALSA lib confmisc.c:1251:(snd_func_refer) error evaluating name
ALSA lib conf.c:4259:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:4738:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM default
bbbbbbbbbbb
这是一个运行前的消息“conectando ......”的代码(抱歉,如果表格打破)
#!/usr/bin/python
import pygame
[...]
print "aaaaaaaaaa"
pygame.init()
print "bbbbbbbbbbb"
所以基本上我只是初始化pygame的。可能是什么问题呢?
如果我这样做也会发生这种情况
>>> from pygame import display, init as pyg_init
>>> pyg_init()
ALSA lib confmisc.c:768:(parse_card) cannot find card '0'
ALSA lib conf.c:4259:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
ALSA lib conf.c:4259:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
ALSA lib confmisc.c:1251:(snd_func_refer) error evaluating name
ALSA lib conf.c:4259:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:4738:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM default
这是装载的模块(从“pygame的”)的导入和显示初始化后的列表
pygame.transform
pygame.sndarray
pygame.numpy
pygame._arraysurfarray
pygame.fastevent
pygame.threads.traceback
pygame.version
pygame.surflock
pygame.image
pygame.color
pygame._numpysndarray
pygame.joystick
pygame.overlay
pygame.imageext
pygame.sprite
pygame.mask
pygame.threads.Queue
pygame.pygame
pygame.event
pygame.threads.sys
pygame.threads
pygame.threads.pygame
pygame.scrap
pygame.copy_reg
pygame.movie
pygame.mouse
pygame._numpysurfarray
pygame.pixelarray
pygame.surface
pygame.key
pygame.base
pygame.compat
pygame.sysfont
pygame.colordict
pygame.string
pygame.sys
pygame.re
pygame.cursors
pygame.cdrom
pygame.time
pygame.mixer
pygame.os
pygame.draw
pygame
pygame.rect
pygame.rwobject
pygame.mixer_music
pygame.constants
pygame.surfarray
pygame.threads.threading
pygame.font
pygame.bufferproxy
pygame.display
pygame.init()
尝试初始化所有Pygame的模块,你(documentation)
如果你不希望这种情况发生(它在你的情况听起来像),你必须初始化每个要自己使用的模块。每个模块都使用该模块之前,你可以调用一个方法init
。您也可以拨打init
每个模块多次无任何毒副作用。
最近,我遇到了这个职位,因为我也有类似的问题。当我安装了它,它的模块(我一直在学习图形)pygame的正确工作。然后我得到了主意,安装Kivy,因为我一直想用它,但像往常一样,我不能让它在Ubuntu 16.04(Windows应用程序版本)工作。然后我卸载它和它所有的依赖关系。当我运行一个脚本Pygame的,我是提示:
$ ./timer.py
pygame 1.9.4
Hello from the pygame community. https://www.pygame.org/contribute.html
ALSA lib confmisc.c:768:(parse_card) cannot find card '0'
ALSA lib conf.c:4259:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
ALSA lib conf.c:4259:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
ALSA lib confmisc.c:1251:(snd_func_refer) error evaluating name
ALSA lib conf.c:4259:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:4738:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM default
这驱使我安装ASLA lib和尝试,并按照维基。修修补补,并试图找出什么是错的,我慢慢发现自己被驱动疯狂阅读多线程,直到我碰到jdonalds后:https://raspberrypi.stackexchange.com/questions/83254/pygame-and-alsa-lib-error。他的解决办法是由OS模块中使用os.environ指定不同的SDL默认的声音驱动程序:
import os
os.environ['SDL_AUDIODRIVER'] = 'dsp'
由于我有多个图形脚本,我不想改变,我添加了下面一行到我的.bashrc:
export SDL_AUDIODRIVER='dsp'
驱动程序的可用性依赖于平台和SDL编译时的选项。您还可以了解更多关于SDL常见问题解答以下链接:https://wiki.libsdl.org/FAQUsingSDL