Python pygame尝试使用alsa

Python pygame尝试使用alsa,python,pygame,alsa,Python,Pygame,Alsa,当我试图运行一个使用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

当我试图运行一个使用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…”之前运行的代码(如果表格出现中断,请抱歉)

所以本质上我只是初始化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
这是导入display和init后加载的模块列表(以“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模块()

如果您不希望发生这种情况(在您的案例中听起来很像),那么您必须自己初始化要使用的每个模块。每个模块都有一个
init
方法,您可以在使用该模块之前调用该方法。您还可以为每个模块多次调用
init
,而不会产生任何副作用。

pygame.init()
尝试为您初始化所有pygame模块()


如果您不希望发生这种情况(在您的案例中听起来很像),那么您必须自己初始化要使用的每个模块。每个模块都有一个
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库并尝试跟随wiki。在修修补补并试图找出问题所在后,我慢慢发现自己被阅读多个线程逼疯了,直到我看到jdonalds的帖子:。他的解决方案是在操作系统模块中使用os.environ指定不同的SDL默认声音驱动程序:

import os
os.environ['SDL_AUDIODRIVER'] = 'dsp'
由于我有多个不想更改的图形脚本,因此我将以下行添加到我的.bashrc

export SDL_AUDIODRIVER='dsp'

驱动程序的可用性取决于平台和SDL编译时选项。您还可以通过以下链接了解有关SDL常见问题解答的更多信息:

我最近遇到了这篇文章,因为我也遇到了类似的问题。当我安装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库并尝试跟随wiki。在修修补补并试图找出问题所在后,我慢慢发现自己被阅读多个线程逼疯了,直到我看到jdonalds的帖子:。他的解决方案是在操作系统模块中使用os.environ指定不同的SDL默认声音驱动程序:

import os
os.environ['SDL_AUDIODRIVER'] = 'dsp'
由于我有多个不想更改的图形脚本,因此我将以下行添加到我的.bashrc

export SDL_AUDIODRIVER='dsp'

驱动程序的可用性取决于平台和SDL编译时选项。您还可以通过以下链接了解有关SDL常见问题解答的更多信息:

谢谢。我在显示器和字体上运行了init,非常感谢。我在显示器和字体上运行了init,已经过去了好几年了,你救了我,伙计!谢谢你,我一直在疯狂地寻找解决方案,一个在互联网上似乎没有人帮助我解决问题,然后我来这里找到你的解决方案,它的工作!!!谢谢你,我能帮上忙。:)岁月流逝,你救了我,伙计!谢谢你,我一直在疯狂地寻找解决方案,一个在互联网上似乎没有人帮助我解决问题,然后我来这里找到你的解决方案,它的工作!!!谢谢你,我能帮上忙。:)