psychopy.org | Reference | Downloads | Github

Issue with Export to HTML using variable-defined condition file in loop: NameError, UnboundLocalError

URL of code: eval_pointing_1

Description of issue:
I am trying to export my experiment to HTML, and it fails every time I use a variable-defined condition file in one of my trial loops. This is used to randomize conditions.

Earlier in the experiment I define a config file by variable in a practice trial loop, and that causes no issues. Both config file name variables are declared in the same place - right at the start of the experiment.

I have verified that this is the cause of the issue by hard-coding one of the two config files in the loop. PsychoPy will then export to HTML and the experiment runs fine.

I could workaround this, but this will take a lot of effort to implement, so I am hoping there is a way to resolve this export error.

Appreciate any help!

Stdout of the Export to HTML below

pygame 1.9.6
Hello from the pygame community. Contribute - pygame wiki
6.9069 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’, ‘PTB’, ‘pyo’, ‘pygame’] (in that order).
7.7128 WARNING duplicate variable names: inst_panel
Alert 4051: Experiment was built in a future version of PsychoPy (2021.1.4), we recommend either updating PsychoPy or changing the “Use Version” setting in Experiment Settings to this version.
For more info see https://docs.psychopy.org/alerts/4051.htmlTraceback (most recent call last):
File “C:\Users\Vision Lab\AppData\Roaming\psychopy3\versions\psychopy\experiment_experiment.py”, line 816, in findPathsInFile
filePath = eval(filePath)
File “”, line 1, in
NameError: name ‘block_config_csv’ is not defined

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “C:\Program Files\PsychoPy3\lib\runpy.py”, line 193, in _run_module_as_main
main”, mod_spec)
File “C:\Program Files\PsychoPy3\lib\runpy.py”, line 85, in _run_code
exec(code, run_globals)
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\scripts\psyexpCompile.py”, line 250, in
compileScript(args.infile, args.version, args.outfile)
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\scripts\psyexpCompile.py”, line 242, in compileScript
makeTarget(thisExp, outfile, targetOutput)
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\scripts\psyexpCompile.py”, line 214, in makeTarget
script = thisExp.writeScript(outfile, target=targetOutput, modular=True)
File “C:\Users\Vision Lab\AppData\Roaming\psychopy3\versions\psychopy\experiment_experiment.py”, line 220, in writeScript
localDateTime, modular)
File "C:\Users\Vision Lab\AppData\Roaming\psychopy3\versions\psychopy\experiment\components\settings_init
.py", line 528, in writeInitCodeJS
self.prepareResourcesJS()
File "C:\Users\Vision Lab\AppData\Roaming\psychopy3\versions\psychopy\experiment\components\settings_init
.py", line 516, in prepareResourcesJS
resourceFiles = self.exp.getResourceFiles()
File “C:\Users\Vision Lab\AppData\Roaming\psychopy3\versions\psychopy\experiment_experiment.py”, line 864, in getResourceFiles
condsPaths = findPathsInFile(params[‘conditionsFile’].val)
File “C:\Users\Vision Lab\AppData\Roaming\psychopy3\versions\psychopy\experiment_experiment.py”, line 830, in findPathsInFile
files.extend(findPathsInFile(str(condFile)))
File “C:\Users\Vision Lab\AppData\Roaming\psychopy3\versions\psychopy\experiment_experiment.py”, line 847, in findPathsInFile
conds = data.importConditions(thisFile[‘abs’]) # load the abs path
File “C:\Users\Vision Lab\AppData\Roaming\psychopy3\versions\psychopy\data\utils.py”, line 476, in importConditions
(fileName, len(trialList), len(fieldNames)))
UnboundLocalError: local variable ‘trialList’ referenced before assignment
65565.0625 INFO C:\Program Files\PsychoPy3\python.exe -m psychopy.scripts.psyexpCompile C:\Users\Vision Lab\Development\eval_pointing_1\eval_pointing_1.psyexp -o C:\Users\Vision Lab\Development\eval_pointing_1\html\eval_pointing_1.js -v latest

Hello,

solve these problems.

  1. Make your duplicate variable names unique.
  2. Use the proper PsychoPy-version. The various PsychoPy-versions differ in features that components have.
  3. Define block_config_csv.

Best wishes Jens

Hi Jens,

Thanks for the tips.

  1. Resolved, I gave a unique name to each in its respective loop

  2. I had this set to “latest”. I tried: 2021, 2020, 2021.1.4, 2020.2, 2020.1; all of them produced the same error with block_config_csv not defined

  3. This is the crux of the issue. I had declared and assigned this variable, once at the beginning of the script, and then its value is changed right before the trial loop is run. Pictures attached.

Is there any reason why this variable is not defined?

Hello,

you are showing me JS-code. I mostly rely on the auto-translate from Python → JS by PsychoPy and edit the JS only when this fails.

Anyway, could you print the value that block_config_csv at the various places in the experiment to the console and check its value and the values of its indexes? At the moment its value seems to be empty (File = “”.). What do you expect in block_config_csv = block_configs[block_num-1];?

Rather than setting the PsychoPy-version, I would update your Psycho-version to the most current one.

Best wishes Jens

Hi,

Thanks.

I updated to PsychoPy 2021.2.1

I added console output for the values of block_config_csv = block_configs[block_num-1]; and it is correct.

console.log(block_configs) gives Array[“pointing_A3.csv”, “pointing_A4.csv”]
and
console.log(block_config_csv) gives pointing_A3.csv

This is true both at the beginning of the experiment,

and in the block loop (right before block_config_csv is referenced which breaks the compiler)

Still, the HTML compiler will not allow the use of block_config_csv as a variable in the Conditions field of the BlockTrials loop. It says NameError: name ‘block_config_csv’ is not defined

I can think of a workaround. Since there are only two possible block config files, I can make three block routine sequences, back to back, (A3, A4, A3) and disable one of the A3 depending on which block order is randomly chosen. But it is more laborious and will be harder to maintain in the future.

If there is anything else to try, or it could be a bug in PsychoPy, please let me know.