psychopy.org | Reference | Downloads | Github

UnboundLocalError: local variable 'trialList' referenced before assignment

OS (e.g. Win10): mac 10.15.4
PsychoPy version (e.g. 1.84.x): 2020.1.2
Standard Standalone? (y/n) If not then what?: y
What are you trying to achieve?:

I have this old exp that I can still run [github link removed after problem solved ]. I just refactored it: the stimuli are slightly different, but I meant to use the same paradigm [github link removed after problem solved ]. I copied the .psyexp file over, and when I run it, psychopy crushes after instruction presentation and gives me

2020-05-18 23:32:20.511 python[2618:50957] ApplePersistenceIgnoreState: Existing state will not be touched. New state will be written to (null)
Traceback (most recent call last):
  File "/Users/xzfang/Desktop/exp1/popout_cindy_lastrun.py", line 267, in <module>
    trialList=data.importConditions(cur_block_file_name),
  File "/Applications/PsychoPy3.app/Contents/Resources/lib/python3.6/psychopy/data/utils.py", line 417, in importConditions
    (fileName, len(trialList), len(fieldNames)))
UnboundLocalError: local variable 'trialList' referenced before assignment
##### Experiment ended. #####

I am stumped, waiting for help.

This happens for a reason: probably I did something different, but the error message doesn’t make any sense.

So I pip installed psychopy2020.1.2 into my conda python3 env and ran the script from the terminal. Crash, then correct error messages are shown: I fixed it and the script is running now (from both terminal and runner). The runner is not showing correct error messages, a psychopy bug?

Traceback (most recent call last):
  File "popout_cindy_lastrun.py", line 246, in <module>
    trialList=data.importConditions(cur_block_file_name),
  File "/Users/xzfang/anaconda3/lib/python3.7/site-packages/psychopy/data/utils.py", line 285, in importConditions
    trialList, fieldNames = pandasToDictList(trialsArr)
  File "/Users/xzfang/anaconda3/lib/python3.7/site-packages/psychopy/data/utils.py", line 248, in pandasToDictList
    _assertValidVarNames(fieldNames, fileName)
  File "/Users/xzfang/anaconda3/lib/python3.7/site-packages/psychopy/data/utils.py", line 223, in _assertValidVarNames
    (fileName, msg, os.linesep * 2, name))
ValueError: Conditions file tBlock01.csv: Parameters (column headers) cannot contain punctuation or spaces

"distractor_color_condition.tolist"
0.5678 	WARNING 	We strongly recommend you activate the PTB sound engine in PsychoPy prefs as the preferred audio engine. Its timing is vastly superior. Your prefs are currently set to use ['sounddevice', 'pyo', 'pygame'] (in that order).
1.9216 	WARNING 	Import Error: No module named 'psychtoolbox'. Using event module for keyboard component.
4.3426 	WARNING 	User requested fullscreen with size [1536  864], but screen is actually [1440, 900]. Using actual size

Hi,

I’m currently receiving the same error message about ‘trialList’ being referenced before assignment. What did you do to fix it? Any help would be much appreciated.

Thanks