# psychopy.preferences - getting and setting preferences¶

You can set preferences on a per-experiment basis. For example, if you would like to use a specific audio library, but don’t want to touch your user settings in general, you can import preferences and set the option audioLib accordingly:

from psychopy import prefs
prefs.hardware['audioLib'] = ['pyo']
from psychopy import sound


!!IMPORTANT!! You must import the sound module AFTER setting the preferences. To check that you are getting what you want (don’t do this in your actual experiment):

print sound.Sound


The output should be <class 'psychopy.sound.SoundPyo'> for pyo, or <class 'psychopy.sound.SoundPygame'> for pygame.

You can find the names of the preferences sections and their different options here.

## Preferences¶

class psychopy.preferences.Preferences[source]

Users can alter preferences from the dialog box in the application, by editing their user preferences file (which is what the dialog box does) or, within a script, preferences can be controlled like this:

import psychopy
psychopy.prefs.hardware['audioLib'] = ['PTB', 'pyo','pygame']
print(prefs)
# prints the location of the user prefs file and all the current vals


Use the instance of prefs, as above, rather than the Preferences class directly if you want to affect the script that’s running.

loadAll()[source]

Load the user prefs and the application data

loadUserPrefs()[source]

load user prefs, if any; don’t save to a file because doing so will break easy_install. Saving to files within the psychopy/ is fine, eg for key-bindings, but outside it (where user prefs will live) is not allowed by easy_install (security risk)

resetPrefs()[source]

removes userPrefs.cfg, does not touch appData.cfg

restoreBadPrefs(cfg, result)[source]

result = result of validate

saveAppData()[source]

Save the various setting to the appropriate files (or discard, in some cases)

saveUserPrefs()[source]

Validate and save the various setting to the appropriate files (or discard, in some cases)

validate()[source]

Validate (user) preferences and reset invalid settings to defaults