pygame tries to use alsa
Asked Answered
R

4

5

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
Retene answered 6/8, 2015 at 5:30 Comment(0)
T
5

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.

Taphouse answered 6/8, 2015 at 5:54 Comment(1)
Thanks. I ran init on display and font and it was enoughRetene
E
13

I recently came across this post, because I had a similar issue. Pygame was working correctly when I installed it and its modules (I have been learning graphics). I then got the idea to install Kivy since I have always wanted to use it, but like usual I couldn't get it working on Ubuntu 16.04 (Windows APP version). I then uninstalled it and all its dependencies. When I ran a pygame script, I was prompted with:

$ ./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

This drove me install the ASLA lib and try and follow the wiki. After tinkering and trying to figure out what was wrong, I slowly found myself being driven insane by reading multiple threads, until I came across jdonalds post: https://raspberrypi.stackexchange.com/questions/83254/pygame-and-alsa-lib-error. His solution was to specify a different SDL default sound driver by using os.environ in the os module:

import os
os.environ['SDL_AUDIODRIVER'] = 'dsp'

Since I have multiple graphics scripts that I dont want to change, I added the following line to my .bashrc:

export SDL_AUDIODRIVER='dsp'

The drivers availability depend on the platform and SDL compile-time options. You can also learn more about FAQ on SDL at the following link: https://wiki.libsdl.org/FAQUsingSDL

Ericaericaceous answered 3/2, 2019 at 23:39 Comment(0)
T
5

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.

Taphouse answered 6/8, 2015 at 5:54 Comment(1)
Thanks. I ran init on display and font and it was enoughRetene
L
0

Experienced this while using gym in colab solved by commenting out the python env.render() for training.

On local windows machine (doesnt have audio output) plugged in my earphones.

Letreece answered 25/2, 2022 at 12:20 Comment(0)
J
0

Try running this in an virtual environment, with python 3.8.16 and downloading all the packages there first. The virtual environment could solve the OS level issues.

Jackiejackinoffice answered 17/6 at 3:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.