very persistant NameError

678 views
Skip to first unread message

Lily FitzGibbon

unread,
Jul 24, 2013, 9:28:44 AM7/24/13
to psychop...@googlegroups.com
Please help! I have just come back to an experiment I started working on some time ago and it wont run because of a NameError. I have tried all the fixes recommended on here including unchecking reloadPrevFiles. When I import the conditions file it shows the problem variable as one of the parameters. The text component is set to repeat every trial. I have updated to the latest version. I have tried running your demos (see error message below) and am faced with the same problem. I have tried starting again with the experiment from scratch and the same error comes up. What am I missing? I am now running PsychoPy version v1.77.02 on OS X 10.7.4.

Traceback (most recent call last):
  File "/Users/Lily/Dropbox/Psychopy/stroop/stroop_lastrun.py", line 157, in <module>
    word.setColor(letterColor, colorSpace='rgb')
NameError: name 'letterColor' is not defined

Many thanks,

Lily

Jonathan Peirce

unread,
Jul 24, 2013, 10:37:50 AM7/24/13
to psychop...@googlegroups.com
Possibilities:
- Is the routine in which your `word` component appears occuring
before the loop where you import the appropriate conditions file?
- are you sure the case of the variable is the same (LetterColor is
not letterColor)?
- are there any hidden characters in the name inthe excel file?
e.g. if `letterColor` is actually written as `letterColor ` with a space

If none of those work then send the files to run the study - I'm sure
it's a really simple fix in the end.

Jon
> --
> You received this message because you are subscribed to the Google
> Groups "psychopy-users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to psychopy-user...@googlegroups.com.
> To post to this group, send email to psychop...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/psychopy-users/5d6bcd95-42f9-455c-8740-95397aa382ec%40googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

--
Jonathan Peirce
Nottingham Visual Neuroscience

http://www.peirce.org.uk

This message and any attachment are intended solely for the addressee and may contain confidential information. If you have received this message in error, please send it back to me, and immediately delete it. Please do not use, copy or disclose the information contained in this message or in any attachment. Any views or opinions expressed by the author of this email do not necessarily reflect the views of the University of Nottingham.

This message has been checked for viruses but the contents of an attachment
may still contain software viruses which could damage your computer system, you are advised to perform your own checks. Email communications with the University of Nottingham may be monitored as permitted by UK legislation.




Lily FitzGibbon

unread,
Jul 24, 2013, 11:11:30 AM7/24/13
to psychop...@googlegroups.com
Thanks for the speedy response. Weirdly the error comes up even for your Stroop demo. I have attached the files for the experiment I am working on here.

Thanks again,

Lily
Reading2.psyexp
ReadingConditions.xlsx

Jonathan Peirce

unread,
Jul 26, 2013, 5:29:45 AM7/26/13
to psychop...@googlegroups.com
I'm afraid I have no idea what could be causing that error for the included demos. Sounds like something is broken on your system or your installation. But I've no idea what. The experiment you attached runs fine on my machine!

Jon

For more options, visit https://groups.google.com/groups/opt_out.
 
 
-- 
Jonathan Peirce
Nottingham Visual Neuroscience

engas...@gmail.com

unread,
Nov 27, 2013, 1:07:08 PM11/27/13
to psychop...@googlegroups.com
Hello,

I am having a very similar problem.

I am trying to have many different images display and randomize them.  I am using a loop and a .xlsx file where the first row of the first column is called ImageName and each subsequent row is a filepath to an image.  This task works fine on my PC but when I try to run the exact same task with nothing changed from the computer in the lab I get an error:

image.setImage(ImagePath)
NameError: name 'ImagePath' is not defined

I tried running stroop and receive a similar error:

word.setColor(letterColor, colorSpace='rgb')
NameError: name 'letterColor' is not defined

X conditions with Y parameters is showing up properly in the trials Properties and the image Properties Image is set to set every repeat, not constant.

I am using Windows XP and Python 3.3 and PsychoPy v1.77.02

Thanks for any help,
Elena

Monique Murphy

unread,
Feb 18, 2014, 3:59:03 PM2/18/14
to psychop...@googlegroups.com
I have the same error. When I first installed PsychoPy about a year ago, I went through the Stroop task tutorial, everything worked great, I did a whole experiment in fall of 2013 using sound presentation with no problems.

Now I am trying to create a similar experiment, and every time I try to run, it says the name of my variable is not defined. In Coder view, the Excel file (with the variable name/conditions) is being loaded long after the script is calling for the name of the variable, but I'm not sure what I should be moving and where. For example, in my Excel file, there is a list of five .wav files in a column called "soundFile," but when I run, it says "error: soundFile is not defined."

I'm open to fixing this with the Coder view, although I am a Python beginner, but I'm not sure what order to put blocks of code in if not the order created by Builder. I've attached the experiment, my sound files, and my Excel file, if anyone is willing to take a crack at it.
wordrepetition.zip

Jeremy Gray

unread,
Feb 18, 2014, 4:18:11 PM2/18/14
to psychop...@googlegroups.com
Just an idea: Maybe this is related to the bug in which names like $soundFile were losing their capitalization, becoming $soundfile. So I would try $soundfile (i.e., all lower case) in the field for word.

--Jeremy


Monique Murphy

unread,
Feb 19, 2014, 5:07:36 PM2/19/14
to psychop...@googlegroups.com
Nope, tried it, same error: name "soundfile" is not defined.

Michael MacAskill

unread,
Feb 19, 2014, 5:13:34 PM2/19/14
to psychop...@googlegroups.com
Hi Monique,

Looking at your original message again, it sounds like the problem is likely due to needing to select "set every repeat" rather than "constant" in the Sound field of your Sound component.

Regards,

Michael

Monique Murphy

unread,
Feb 20, 2014, 11:52:38 AM2/20/14
to psychop...@googlegroups.com
Dear Michael,

I have changed it to "constant" and receive the same error.

--Monique

Monique Murphy

unread,
Feb 20, 2014, 12:02:22 PM2/20/14
to psychop...@googlegroups.com
This also doesn't explain why the Stroop task from the demo doesn't work, even though I followed every direction to the letter, and have done the demo previously.

It's as if it's loading the definition for the variable too far down in the script, but asking for the definition early (for example, in the Stroop task, $word is the text that should be displayed from the conditions.xlsx file. In the Coder view, "word" is called on line 55, but the conditions.xlsx file, which should tell the program what value to give $word, is not imported until line 67).

Monique Murphy

unread,
Feb 20, 2014, 12:13:31 PM2/20/14
to psychop...@googlegroups.com
I was able to fix the Stroop task by moving the following code from the commented section "# Initialize components for Routine "trial"" to under the section commented "    #------Prepare to start Routine "trial"-------". I put

target = visual.TextStim(win=win, ori=0, name='target',
    text
=word,    font='Arial',
    pos
=[0, 0], height=0.1, wrapWidth=None,
    color
=1.0, colorSpace='rgb', opacity=1,
    depth
=0.0)


underneath

   t
= 0
    trialClock
.reset()  # clock
    frameN
= -1)


This didn't work for my own experiment, however. Moving the line that calls "soundfile" to later in the script no longer gives me an error, but the experiment starts and then immediately exits.

Monique Murphy

unread,
Feb 20, 2014, 12:16:10 PM2/20/14
to psychop...@googlegroups.com
Okay, actually, I just fixed this error using the same technique, only further down in the script. PsychoPy is definitely loading the variables out of order if you use Builder view, creating a NameError for whatever the name of your condition is.

Michael MacAskill

unread,
Feb 20, 2014, 3:46:59 PM2/20/14
to psychop...@googlegroups.com
Hi Monique,

I finally received your initial attachment (my University blocks zip files and it takes ages for them to be released).

Simply changing to "set every repeat" does indeed solve the problem and your task runs fine for me on PsychoPy 1.79.01 (although I had to change some paths and filenames: you should ideally use a relative rather than absolute path to refer to your conditions file).

> It's as if it's loading the definition for the variable too far down in the script, but asking for the definition early (for example, in the Stroop task, $word is the text that should be displayed from the conditions.xlsx file. In the Coder view, "word" is called on line 55, but the conditions.xlsx file, which should tell the program what value to give $word, is not imported until line 67).
This is exactly what happens when choosing "constant". You are telling Builder that the value to be used won't change, so it creates the component with that fixed attribute at the beginning of the experiment. If you select "set every repeat", it just creates a dummy value (e.g. for sounds, this is the note 'A') to initialise the sound object. It knows that eventually at some point a loop will be created and the variable will become available to use, which will replace the dummy value 'A'. For text stimuli, the dummy value is 'nonsense' I think.

> Okay, actually, I just fixed this error using the same technique, only further down in the script. PsychoPy is definitely loading the variables out of order if you use Builder view, creating a NameError for whatever the name of your condition is.

PsychoPy isn't "loading variables out of order". It is designed to work this way (optimising by initialising objects at the start of the script to avoid delays later on, using dummy values if needed). Rather, what you are doing is creating a contradiction: saying the value will be constant, but then feeding Builder a variable name. It gets confused, because as you have noticed, the variable isn't created until after the sound object is initialised.


Regards,

Michael
Reply all
Reply to author
Forward
0 new messages