Experiment crashes before starting. "name 'Pos_1' is not defined"

If this template helps then use it. If not then just delete and start from scratch.

OS (e.g. Win10): Win10
PsychoPy version (e.g. 1.84.x): v2022.2.5
Standard Standalone? (y/n) If not then what?:
What are you trying to achieve?: I am designing an incentivized facial emotion recognition task in the builder (I don’t know how to code). I want to insert a pair of images (2 photos of the same face portraing the same emotion but in different stages, i.e., neutral and semi-complete emotional expression). I am having a difficult time dealing with this. I’ve created several .xlsx documents (one with the responses the subjects will have to choose from, another one with the reward, the colour of the cue and the feedback, one with the photos, and a last one with the positions for the photos). I am getting the following message: NameError: name ‘Pos_1’ is not defined. Pos_1 is the name I’ve given to the column in the .xlsx doc. that houses the position of the photo that will be appearing on the left (and I guess the same happens with Pos_2, although I haven’t got any message regarding it yet).

**What did you try to make it work?:**I have been reading other similar posts, but they require coding, something I don’t know much about yet. I have also checked each individual loop and routine’s properties. I have tried to display the coordinates for the position of the photos in different ways: (0.4,0) in the same column; separating them into x and y; and also not using the .xlsx doc., and indicating the coordinates in the properties of the images in the routines. This last one renders some results, but it crashes again and I get the following message: AttributeError: ‘str’ object has no attribute ‘setText’

What specifically went wrong when you tried that?:
I am always getting a message saying there is a variable I have not defined, or no attribute.


well, I assume that you could put everything in one Excel-file. You probably get the error because you are referring to Pos_1 before it is know to PsychoPy. Do you mind showing us your Excel-file(s) and the flow of your experiment?

Best wishes Jens

Thank you for your answer! I am attaching the Excel files I am using and a screenshot of the builder view with the routines & flow.

This one sets the reward condition and the colour of the cue, also the feedback given depending on the reward condition. Task_Stimuli.xlsx (8.7 KB)

This one contains the pictures of the faces. Conditions_Stimuli.xlsx (9.0 KB)

This other one contains the answer options. Emotion_Responses.xlsx (8.6 KB)

This one contains the coordinates for the pictures on the screen. Positions.xlsx (9.0 KB)

This is the screenshot.


when and where do you all Pos_1? To which loop does the condition-file with the positions belong?

You have three loops but four condition-files? How does that work out? It looks rather complicated to spread out all this information in four condition-files.

There is no need to define a new routine for each event in a trial.

Are your stimuli picture/images? There are no file-extensions in your stimulus-file. This will fail when running the experiment online.

Best wishes Jens


I sent you the Excel files I am using, but in the screenshot I shared I was not using the Positions one (I just indicated the coordinates in the properties of the images in the routine). But I have set in other attempts a new loop for the positions. Would it be better to have only one Excel doc. with all the conditions? I am afraid that the reward condition will stop working if I do so.

Yes, the stimuli in the Conditions_Stimuli doc. are images of faces portraying emotional expressions. I have set the images routines to look for the folder where I have the images stored. That part was working fairly well until recently. The fact is I am having lots of problems with this experiment: when it doesn’t fail for one thing, it fails for another.

Thank you for your pacience and attention, Chema

Hello Chema,

one step after another. It is not uncommon that when you solve one problem in programming, another shows up. This is simply because the first error stopped the program from running. So, try to solve the error message about Pos_1 first.

Well, I don’t know your experimental restrictions so I can’t really tell you if it is better to use just one Excel-file instead of four. I just assume that.

But my question was, you have four Excel-file but there are only three loops. Usually one Excel-file goes with one loop.

The attached experiment displays the filename of Stimuil_1 and Stimuili_2 at the position Pos_1 and Pos_2. Filename and position are read from the Excel-file Positions.xlsx

VarPos.psyexp (9.6 KB)
Positions.xlsx (9.1 KB)

Best wishes Jens

Dear Jens,

I have fixed what you stressed about having the same .xlsx files as loops.

I really thank you your patience, and also sending me those files so I can have a better understanding.

I used the Positions Excel-file in my experiment - I changed the names of the pictures, so I updated this on your Positions Excel - and I can now see a screen with a pair of images, but it stil crashes (this time under the AttributeError: ‘str’ object has no attribute ‘setText’ message).

I am attaching my experiment so you can properly see what I am doing. I also attach again the .xlsx files. I am not able to upload more than 5 docs. at a time, so do tell me if you need the folder where the images are.

The task: Task - Copy.psyexp (28.9 KB)
The document you created where position and pictures are Positions.xlsx (9.2 KB)
The reward condition, colour of the cue & feedback depending on reward conditionTask_Stimuli.xlsx (8.7 KB)
The answer options Emotion_Responses.xlsx (8.6 KB)

Thank you very much, Chema

Hello Chema,

One can’t run the experiment if one doesn’t have the stimuli. :wink: :stuck_out_tongue_winking_eye: So, for testing purposes, it is often best to make a toy example of your experiment and post that instead of your original experiment.

However, there is one problem that stands out. You have named a text-component response in the routine Response and ins the text-property of this text-component you also specify $response. It is a condition you set up in Emotion_responses.xlsx. You must use unique names, for example respText and respStim.

Best wishes Jens