| Reference | Downloads | Github

OSError: Couldn't find image imageFile; check path?

Hi guys, I’m trying to code up an experiment that shows images, with text overlaid on it.

I created an excel spreadsheet looking like this:

This is the file I’m trying to use.

I get an error message saying:
OSError: Couldn’t find image imageFile; check path? (tried: C:\Users\Sophie\OneDrive\Spring '19\Research\PsychoPy\Bejj\imageFile)

Is there anything wrong with my code? These are the bits I think are relevant:

thisExp = data.ExperimentHandler(name=expName, version='',
    extraInfo=expInfo, runtimeInfo=None,
    savePickle=True, saveWideText=True,
# save a log file for detail verbose info
logFile = logging.LogFile(filename+'.log', level=logging.EXP)
logging.console.setLevel(logging.WARNING)  # this outputs to the screen, not a file

endExpNow = False  # flag for 'escape' or other condition => quit the exp```

and later...

#read stimuli file
trials = open('cog2.csv', 'r')
imageFile = 0     #imageFile = trials[trialNumber][Column]
corrAns = 1       #corrAns = trials[trialNumber][Column]
Congruent = 2     #Congruent = trials[trialNumber][Column]
stimCat = 3       #stimCat = trials[trialNumber][Column]
Superimposed = 4  #Superimposed = trials[trialNumber][Column]
Word = 5          #word = trials[trialNumber][Column]

#turn the text string into stimuli
textStimuli = []
imageStimuli = []
for trial in csv.reader(trials):
    textStimuli.append(visual.TextStim(win, text=trial[Word]))
    imageStimuli.append(visual.ImageStim(win, size=[0.5, 0.5], image=trial[imageFile]))

Hi, it is really useful to paste the entire error message. This would include the trace of line numbers in the code, giving the exact location of the error.

In this case, the error message doesn’t seem consistent with the lines that you have provided (i.e. for some reason you define imageFile as a constant value of 0, and try to use that to index a dictionary in the last line of code, but the error seems to imply that that variable contains the literal text 'imageFile').

You might find it easier to use the TrialHandler class ( to do this task for you (of reading in a conditions file and assigning values from it on each trial). Or do you need to pre-allocate all of the images for performance reasons?