Search code examples
pythonpygamealsa

pygame tries to use alsa


When I try to run a program that uses pygame I get a slow "startup"(init) (4-5s) and this error from ALSA. Fixing ALSA is not my objective, I'd like to know why is it being initialized if I have no use for audio in my code.

$ 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

This is the code that runs prior to the message "conectando..." (sorry if the tabulations break)

#!/usr/bin/python

import pygame

[...]
         print "aaaaaaaaaa"
         pygame.init()
         print "bbbbbbbbbbb"

So essentially I just initialize pygame. What could be wrong with this?

This also happens if I do this

>>> 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

This is the list of modules that are loaded (starting with "pygame") after importing display and init

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

Solution

  • pygame.init() tries to initialize all the pygame modules for you (documentation)

    If you don't want this to happen (which it sounds like in your case), you have to initialize each of the modules that you want to use on your own. Each module has an init method that you can call before you use the module. You can also call init for each module multiple times without any side effects.