psychopy.org | Reference | Downloads | Github

AttributeError: pyo server not created

sound

#1

OS: Win10
PsychoPy version: 1.90.3
Standard Standalone (downloaded/installed just a couple weeks ago)

I have an experiment that I made using the builder that uses a microphone component (here, called Stella_rec). The script worked fine on my old Windows 7 machine, but now I’m trying to run it on my new Dell Windows 10 machine, which has never been connected to the Internet. The experiment initializes, but it closes right before the routine with the microphone component and gives this error:

File “D:\GoogleDriveCurrent\Current\RESEARCH\RATE\RateSali\RateSali.py”, line 489, in
Stella_rec = microphone.AdvAudioCapture(name=‘Stella_rec’, saveDir=wavDirName, stereo=False)
File “C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy\microphone.py”, line 381, in init
buffering=buffering, chnl=chnl, stereo=stereo)
File “C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy\microphone.py”, line 170, in init
raise AttributeError(‘pyo server not created’)
AttributeError: pyo server not created

On my Windows 7 machine, I get the same error if I remove pyo from the audio library field in the PsychoPy preferences window. Lines 168-170 in microphone.py appear to be checking if there is a pyo server:

    # pyo server good to go?
    if not pyo.serverCreated():
        raise AttributeError('pyo server not created')

I can’t find a pyo library on either of my machines, so I don’t know what to fix so that a pyo server can be created.


#2

I am getting the same error. I am just trying to run the demo on Win7 with the newest version (3.0.0b11) but it says AttributeError: pyo server not created. I am trying to use a usb microphone but I’m not sure if I need to tell PsychoPy where the mic is or something. The code works fine on my laptop using the built in mic but it seems like on my desktop it doesn’t know that a mic is plugged in. Anyone know how to tell it where the mic is?


#3

Try changing the audio settings on the computer – Control Panel > Sound > Recording tab > click on desired mic > set as default – and make sure it’s receiving sound (the green bar moves). In the end, I used a different mic – I don’t know if its drivers didn’t play well with PsychoPy or what, but that did it.


#4

I get the same error from running the following lines in the Coder, and changing the default recording device doesn’t solve the problem for me:

from psychopy import microphone
import os

wavDirName = 'Test_wav'
if not os.path.isdir(wavDirName):
    os.makedirs(wavDirName) # make folder to hold .wav files

microphone.switchOn(sampleRate=16000)
my_microphone = microphone.AudioCapture(saveDir=wavDirName)

The error is:

  File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\microphone.py", line 170, in __init__
    raise AttributeError('pyo server not created')

Are there any other ways to solve this problem?


#5

@LukasPsy Did you manage to fix it?


#6

Hi @oren,

back when I had the problem, I ended up using soundfile and sounddevice instead of the psychopy microphone module to record audio.
I’ve just rerun my psychopy code with PsychoPy v3.0.4 and set preferences to pyo to avoid the warning about sounddevice, and it ran without an error. So the problem seems to be resolved in psychopy3.

from psychopy import prefs
prefs.hardware['audioLib'] = ['pyo']
# You must import the sound module AFTER setting the preferences. 
# There are 3 choices of sound libraries (cf. http://www.psychopy.org/api/sound.html)

from psychopy import microphone
import os

wavDirName = 'Testfolder'
if not os.path.isdir(wavDirName):
    os.makedirs(wavDirName) # make folder to hold .wav files

microphone.switchOn(sampleRate=16000)

my_microphone = microphone.AudioCapture(saveDir=wavDirName)

my_microphone.record(sec=2.0) # start the recording thread

#7

@LukasPsy
Thanks,
I tried your code and get the error:

    prefs.hardware['audioLib'] = ['pyo']
AttributeError: 'Preferences' object has no attribute 'hardware'

#8

What version of python are you running? In older versions, the command to change the audio lib was a different one.


#9

@LukasPsy I use Python3.5 and PsychoPy 1.90.2


#10

I don’t remember the command to change preferences in this version. You can try to figure it out by calling dir(prefs) or you can change the preferences through the app by going to file tab => preferences => hardware and put you first in the line for audio library.


#11

@LukasPsy What app are you reffering to? I am using code and not the builder.

dir(prefs)

returns :
'__class__ , __delattr__ , __dict__ , __dir__ , __doc__ , __eq__ , __format__ , __ge__ , __getattribute__ , __gt__ , __hash__ , __init__ , __le__ , __lt__ , __module__ , __ne__ , __new__ , __reduce__ , __reduce_ex__ , __repr__ , __setattr__ , __sizeof__ , __str__ , __subclasshook__ , __weakref__ , _validator , app , appData , appDataCfg , builder , coder , connections , general , getPaths , keys , loadAll , loadAppData , loadUserPrefs , paths , prefsSpec , resetPrefs , restoreBadPrefs , saveAppData , saveUserPrefs , userPrefsCfg , validate

Any idea which I should use?


#12

Does prefs.general['audioLib']=['pyo'] work?


#13

I was referring to the PsychoPy coder app, the editor you are probably using to code.


#14

@LukasPsy Actually I use pyCharm - does it matter?

Your code

prefs.general['audioLib']=['pyo'] 

Worked but still got the error

my_microphone = microphone.AudioCapture(saveDir=wavDirName)
raise AttributeError('pyo server not created')
AttributeError: pyo server not created

#15

Do you have a particular reason for not upgrading to PsychoPy3?


#16

@LukasPsy upgraded to PsychoPy3 - still get the same error


#17

Are you working with a 64-bit python? Because pyo runs only on 32-bit python if this post is still up to date.