# KeyError: ‘audioLib’

**URL:** <https://discourse.psychopy.org/t/keyerror-audiolib/19338>\
**Category:** Coding\
**Created:** [January 3, 2021, 12:22pm UTC](https://discourse.psychopy.org/t/keyerror-audiolib/19338 "2021-01-03T12:22:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sam\_Leak](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/sam_leak/32/2347_2.png) [@Sam\_Leak](https://discourse.psychopy.org/u/Sam_Leak)\
**Post date:** [January 3, 2021, 12:22pm UTC](https://discourse.psychopy.org/t/keyerror-audiolib/19338/1 "2021-01-03T12:22:57Z")

</div>

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/full\_training.py”, 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?

---

<div class="post-metadata">

**Author:** ![jon](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jon/32/22_2.png) [@jon](https://discourse.psychopy.org/u/jon)\
**Post date:** [January 3, 2021, 3:28pm UTC](https://discourse.psychopy.org/t/keyerror-audiolib/19338/2 "2021-01-03T15:28:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Sam\_Leak](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/sam_leak/32/2347_2.png) [@Sam\_Leak](https://discourse.psychopy.org/u/Sam_Leak)\
**Post date:** [January 3, 2021, 3:41pm UTC](https://discourse.psychopy.org/t/keyerror-audiolib/19338/3 "2021-01-03T15:41:57Z")

</div>

Thanks a lot, Jon!

I updated it to:

> import psychopy  
> psychopy.useVersion(‘1.90.2’)  
> 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](https://discourse.psychopy.org/t/pygame-not-present-in-psychopy-2020-2-4-on-macos/16942/3)? 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…).

---

<div class="post-metadata">

**Author:** ![jon](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jon/32/22_2.png) [@jon](https://discourse.psychopy.org/u/jon)\
**Post date:** [January 3, 2021, 7:54pm UTC](https://discourse.psychopy.org/t/keyerror-audiolib/19338/4 "2021-01-03T19:54:41Z")

</div>

> [@Sam\_Leak](#):
>
> 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)
