Hi,
I’m encountering some issues with installing Psychopy 1.90.1 on both Windows 10 and Windows 7 64bit machines. There seems to be (and this is a guess) a fundamental problem in loading the python libraries. For example, when I try to run the following code
from psychopy import core, event, visual, sound, logging, gui, data
from numpy.random import random, randint, normal, shuffle
import pandas as pd # these are for reading from excel files
import random, os, csv, glob, sys
# Ensure that relative paths start from the same directory as this script
_thisDir = os.path.dirname(os.path.abspath(__file__)).decode(sys.getfilesystemencoding())
os.chdir(_thisDir)
#launches a GUI to get info
expName = u'incomplete letters'
expInfo = {'participant': "",'condition':'1'}
dlg = gui.DlgFromDict(dictionary=expInfo, title=expName)
if dlg.OK == False:
core.quit() # user pressed cancel
expInfo['date'] = data.getDateStr() # add a simple timestamp
expInfo['expName'] = expName
# start a clock for the reaction times
rtimer=core.Clock()# general purpose clock
# Data file name stem for saving data = absolute path + name; later add .psyexp, .csv, .log, etc
filename = _thisDir + os.sep + u'data/%s_%s_%s' % ('P'+expInfo['participant'], 'C'+expInfo['condition'],expName)#, expInfo['date'] # took date out cause it was annoying
# this experiment handler simplifies the saving of data a bit
exp = data.ExperimentHandler(name='incomplete_letters',version='0.1',runtimeInfo=None,originPath=None,savePickle=False,saveWideText=True,dataFileName=filename)
# set up your window
win = visual.Window( units='deg',monitor='office',fullscr=True) #size=(800, 800),
win.setMouseVisible(False)
################################ SET UP STIMULI ###################################
#read in the whole excel file, you can specify the sheet if you need to
filename1=_thisDir + '\incomplete letters stimuli list.xlsx'
datast = pd.read_excel(filename1)
# build lists with the values from the excel files
images_a = datast['file1'].values
images_b = datast['file2'].values
images_c = datast['file3'].values
images_d = datast['file4'].values
images_e = datast['file5'].values
images_f = datast['file6'].values
images_g = datast['file7'].values
images_h = datast['file8'].values
images_i = datast['file9'].values
images_j = datast['file10'].values
images_k = datast['file11'].values
images_l = datast['file12'].values
images_m = datast['file13'].values
images_n = datast['file14'].values
images_o = datast['file15'].values
images_p = datast['file16'].values
images_q = datast['file17'].values
images_r = datast['file18'].values
images_s = datast['file19'].values
images_t = datast['file20'].values
images_u = datast['file21'].values
images_v = datast['file22'].values
images_w = datast['file23'].values
images_x = datast['file24'].values
images_y = datast['file25'].values
images_z = datast['file26'].values
image_list=[images_a,images_b,images_c,images_d,images_e,images_f,images_g,images_h,images_i,images_j,images_k,images_l,images_m,images_n,images_o,images_p,images_q,images_r,images_s,images_t,images_u,images_v,images_w,images_x,images_y,images_z]
answers_a = datast['answer1'].values
answers_b = datast['answer2'].values
answers_c = datast['answer3'].values
answers_d = datast['answer4'].values
answers_e = datast['answer5'].values
answers_f = datast['answer6'].values
answers_g = datast['answer7'].values
answers_h = datast['answer8'].values
answers_i = datast['answer9'].values
answers_j = datast['answer10'].values
answers_k = datast['answer11'].values
answers_l = datast['answer12'].values
answers_m = datast['answer13'].values
answers_n = datast['answer14'].values
answers_o = datast['answer15'].values
answers_p = datast['answer16'].values
answers_q = datast['answer17'].values
answers_r = datast['answer18'].values
answers_s = datast['answer19'].values
answers_t = datast['answer20'].values
answers_u = datast['answer21'].values
answers_v = datast['answer22'].values
answers_w = datast['answer23'].values
answers_x = datast['answer24'].values
answers_y = datast['answer25'].values
answers_z = datast['answer26'].values
answer_list=[answers_a,answers_b,answers_c,answers_d,answers_e,answers_f,answers_g,answers_h,answers_i,answers_j,answers_k,answers_l,answers_m,answers_n,answers_o,answers_p,answers_q,answers_r,answers_s,answers_t,answers_u,answers_v,answers_w,answers_x,answers_y,answers_z]
################################ INSTRUCTIONS ###################################
def instpres(string):
IS=visual.TextStim(win=win, color='black', height=1, text=string, alignHoriz='center',wrapWidth=20)# this is alignment to the screen not the text alignment, irritatingly
IS.draw()
win.flip()
core.wait(3)#prevent accidental presses.
responsegiven=False # set the response counter to false
while not responsegiven:
for key in event.getKeys(): #accept all key presses
if key in (['escape']): # if one of the key presses has been escape then quit
win.close()
core.quit()
elif key in (['space']): # if it matches the response
responsegiven=True
instpres('Hello, you will now see a series of images.\n\n\
Please press the space bar until you can identify a letter\n \n\
When you can identify the letter, press the corresponding key on the keyboard\n \n\
Press the spacebar to start a demonstration.')
################################ LISTS AND RANDOMISATION ###################################
# open empty lists for the responses and reaction times
file=[]
keyspressed=[]
reactiontime=[]
letter_id_time=[]
identification=[]
letter_select = range(0,26)# generate a list of numbers bw 1:26
shuffle(letter_select)# shuffle the list
################################ RUN DEMO ###################################
images=image_list[letter_select[23]]# take the image LIST based on the random 1:26 number
answers=answer_list[letter_select[23]]# and the corresponding correct answer
a=0 # simple counter for the image files
continue_loop=True # continue until they get the correct response
while continue_loop:
file=images[a]#keep a record for the data file of which image was being used
image = visual.ImageStim(win, image=images[a])# draw the image [a]
image.draw()
win.callOnFlip(rtimer.reset)# reset the clock when the image is presented
win.flip()
# rtimer.reset()# set reaction timer to 0
responsegiven=False # set the response counter to false
while not responsegiven:
for key in event.getKeys(): #accept all key presses
if key in (['escape']): # if one of the key presses has been escape then quit
win.close()
core.quit()
elif key in (answers[a]): # if it matches the response
responsegiven=True # then count it as a response
keyspressed.append(key)
rt=rtimer.getTime()
reactiontime.append(rt)
identification = 99-a
continue_loop=False # quit loop because it was correct
elif key not in (answers[a]) or not (['escape']):#stop accidental key presses by the participant.
responsegiven=True # count as a valid response
keyspressed.append(key)
rt=rtimer.getTime()
reactiontime.append(rt)
continue_loop=True # continue on to the next image because it was incorrect
a+=1
################################ FINISH DEMO ###################################
################################ START MAIN EXPERIMENT ###################################
instpres('You are now ready to start the experiment.\n\n\
Press the spacebar to start.')
b=0 # create a counter for the letter list
while b < len(letter_select):#for all 26 letters
images=image_list[letter_select[b]]# take the image LIST based on the random 1:26 number
answers=answer_list[letter_select[b]]# and the corresponding correct answer
letter_start=core.Clock()
a=0 # simple counter for the image files
continue_loop=True # continue until they get the correct response
while continue_loop:
core.wait(0.5)# this stops them pressing the space bar too quickly and skipping through too fast
file=images[a]#keep a record for the data file of which image was being used
image = visual.ImageStim(win, image=images[a])# draw the image [a]
image.draw()
win.callOnFlip(rtimer.reset)# reset the clock when the image is presented
win.flip()
responsegiven=False # set the response counter to false
while not responsegiven:
for key in event.getKeys(): #accept all key presses
if key in (['escape']): # if one of the key presses has been escape then quit
win.close()
core.quit()
elif key in (answers[a]): # if it matches the response
responsegiven=True # then count it as a response
keyspressed.append(key)
rt=rtimer.getTime()
reactiontime.append(rt)
identification = 99-a
continue_loop=False # quit loop because it was correct
elif key not in (answers[a]) or not (['escape']):#stop accidental key presses by the participant.
responsegiven=True # count as a valid response
keyspressed.append(key)
rt=rtimer.getTime()
reactiontime.append(rt)
continue_loop=True # continue on to the next image because it was incorrect
################################################## SAVE TRIAL BY TRIAL RESPONSES ##################################
exp.addData('image file',file)
exp.addData('key_out', keyspressed[-1])#this takes the most recent key press, without the -1 it just tots them all up, it also magically gets rid of the annoying sq brackets
exp.addData('reactiontime', reactiontime[-1])
exp.nextEntry()# this is a critical line, without this it doesn't save the data, it just moves to next line.
################################################## SAVE TRIAL BY TRIAL RESPONSES ##################################
a+=1
letter_id_time=letter_start.getTime()
################################################## SAVE LOOP BY LOOP RESPONSES ##################################
exp.addData('image file1',file)
exp.addData('identification point (%)',identification)
exp.addData('total letter id time',letter_id_time)
exp.nextEntry()
################################################## SAVE LOOP BY LOOP RESPONSES ##################################
b+=1
instpres('Thank you, you have finished.\n\n\
Please wait for your next instruction.')
I get the following error
##### Running: X:\Psychology\ResearchProjects\GStothart\BRACE Pilot 2018\paradigm development\incomplete letters pilot\incomplete letters behavioural.py #####
1.5361 INFO Loaded SoundDevice with PortAudio V19.6.0-devel, revision 396fe4b6699ae929d3a685b3ef8a7e97396139a4
1.5362 INFO sound is using audioLib: sounddevice
Traceback (most recent call last):
File "X:\Psychology\ResearchProjects\GStothart\BRACE Pilot 2018\paradigm development\incomplete letters pilot\incomplete letters behavioural.py", line 13, in <module>
_thisDir = os.path.dirname(os.path.abspath(__file__)).decode(sys.getfilesystemencoding())
AttributeError: 'str' object has no attribute 'decode'
Even if I click on the error, I get another error, which is what is making me think there is something really fundamentally wrong with the install.
Traceback (most recent call last):
File "C:\Program Files (x86)\PsychoPy2_PY3\lib\site-packages\psychopy\app\coder\coder.py", line 2889, in onURL
lineNumber = int(tmpLineNumber.split()[0])
ValueError: invalid literal for int() with base 10: '13,'
I’ve spent some time looking into Python version, manual installs, C++ libraries and .net framework version but to be honest I’m a bit out of my depth. Do you have any pointers for things to check?
FYI my old version of Psychopy, v1.85.1, had none of these problems, worked perfectly and if I roll back to 1.85.1 still works perfectly.
Many thanks
George