Pygame Midi Libasound_Module_Conf_Pulse. So Error + Unable to Open Slave

I was getting this error when I tried to run my pygame.midi code:

ALSA lib conf.c:3558:(snd_config_hooks_call) Cannot open shared library libasound_module_conf_pulse.so (/usr/lib/alsa-lib/libasound_module_conf_pulse.so: libasound_module_conf_pulse.so: cannot open shared object file: No such file or directory)
ALSA lib seq.c:935:(snd_seq_open_noupdate) Unknown SEQ default

I found out that the path Python was searching for did not exist. For some reason, libasound_module_conf_pulse.so is located in /usr/lib/x86_64-linux-gnu/alsa-lib, so I created alsa-lib directory in /usr/lib/ and copied the contents of usr/lib/x86_64-linux-gnu/alsa-lib in it.

That fixed the first error. Now, I am encountering another error, which I think is related to the really shady fix I applied above (why I included both of them in the same question). When running pygame.init() I get this error:

ALSA lib pcm_dmix.c:1089:(snd_pcm_dmix_open) unable to open slave

I have searched the web and found only one question related but sadly left unanswered. What I understand is that using methods from pygame.midi works but using methods from pygame such as init throws the error.

So, this code works fine:

import pygame.midi
import pygame

def print_devices():
    for n in range(pygame.midi.get_count()):
        print (n,pygame.midi.get_device_info(n))

def number_to_note(number):
    notes = ['c', 'c#', 'd', 'd#', 'e', 'f', 'f#', 'g', 'g#', 'a', 'a#', 'b']
    return notes[number%12]

def readInput(input_device):
    clock = pygame.time.Clock()
    while True:
        if input_device.poll():
            event = input_device.read(1)[0]
            data = event[0]
            timestamp = event[1]
            note_number = data[1]
            velocity = data[2]
            if (velocity!=0):
                print (number_to_note(note_number), velocity)



if __name__ == '__main__':
    pygame.midi.init()
    my_input = pygame.midi.Input(3)
    readInput(my_input)
    my_output = pygame.midi.Output(2)
    my_output.note_on(90,120)
    my_output.note_off(90, 120)

but adding pygame.init() throws the slave error.

I am using Ubuntu 20.04 and Python 3.8 in PyCharm.

Edit: Running the above code directly in Python from the terminal does not give the slave error on pygame.init() but will sometimes give a (snd_pcm_recover) underrun occurred error.

1

2 Answers

I had the same issue using PyGame in Blender, the "hack" above, copying the files to /usr/lib/alsa-lib got rid of the error for me and made sounds and PyGame work properly. I only had this issue on Ubuntu, not my Mac. I didn't ever get the "slave" error.

FTR, I am using PyGame to input live MIDI commands from either a keyboard or controller to animate in Blender.

I had the same issue using mido and instead of copying the file I made a symbolic link from /usr/lib64/alsa-lib to /usr/lib/x86_64-linux-gnu/alsa-lib:

sudo ln -s /usr/lib/x86_64-linux-gnu/alsa-lib /usr/lib64/alsa-lib

No copy and works like magic. Enjoy!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

David Miller

David Miller

Executive Financial & Market Analyst

David Miller brings 15 years of experience in global economics, personal finance strategy, and market dynamics. He specializes in turning complex economic trends into actionable insights for everyday readers.

Share this article
Twitter Facebook Pinterest