KeyError: ‘audioLib’

When trying to use the PsychoPy v2020.2.10 to emulate 1.90.2, I’ve included the following code:

from psychopy import prefs
prefs.hardware[‘audioLib’] = [‘pygame’,‘pyo’]

and I’m getting this error:

File “/Users/sam115/Downloads/experiment_folder/”, line 4, in
from psychopy import locale_setup, sound, gui, visual, core, data, event, logging
File “/Users/sam115/.psychopy3/versions/psychopy/sound/ init .py”, line 70, in
for thisLibName in prefs.general[‘audioLib’]:
File “configobj.pyc”, line 554, in getitem
KeyError: ‘audioLib’

Any ideas on how to fix this?

I think this is a change in the structure of the prefs. in recent versions audioLib is a setting in the “hardware” section of the preferences config file but in older versions it was in “general”. If you’re using version 2020.2 then your code should be fine. But if you’ve set it to useVersion('1.90.2') for instance (when you refer to “emulate 1.90.2” then your code will need to be written in the syntax of that version instead

Thanks a lot, Jon!

I updated it to:

import psychopy
from psychopy import prefs
prefs.general[‘audioLib’] = [‘pygame’, ‘pyo’]
prefs.general[‘audioDevice’] = [‘portaudio’]

and that fixed the 'KeyError: ‘audioLib’; error

However, now I’m getting this:

import pygame
ModuleNotFoundError: No module named ‘pygame’

Does this error relate to this? If so then is there an idiot-proof way of paraphrasing ‘Workaround 2: you should be able to get pygame working by installing it to another python3 installation on your system and then pointing PsychoPy preference for additional libs to include that folder’?

I’m very conscious that you passionately hate pygame, but it’s the only way I could find to play MIDI files (crucial to my experiment, unfortunately…).

Ha ha, I don’t think I’d say I passionately hate it, but a) it has poorer timing and b) it’s harder to support than pyglet. For instance, reason it wasn’t included in recent releases is that it includes a bunch of dylib files compiled in a macOS version that means they can’t be code-signed. For recent versions of macOS anything that isn’t code-signed can’t be packaged. So until pygame improves it can’t be supported on Big Sur in the Standalone format. But they won’t be highly motivated to change their build system because very few people would be packaging it into a code-signed app bundle. Pyglet doesn’t supply any binary dylibs, just plain python code, so fewer problems with distributing.

Thanks for explaining why you’re needing pygame though. I think the solution will be to try and find an alternative for playing MIDI files (or you convert the midi files to another format)

1 Like