psychopy.org | Reference | Downloads | Github

"PsychoPy encountered an unhandled internal error" when producing JS code to push to Pavlovia

**OS: Win10
**PsychoPy version: 2020.2.4
**Standard Standalone? y
**What are you trying to achieve?:
I want to run an experiment online. I used an experiment on Pavlovia as a template to develop my own experiment. I cloned the experiment onto my machine, made changed and then encountered problems when attempting to push it onto Pavlovia (please see the error the message below). The problem seems to be with generating JS code. The experiment runs fine in psychoPy, and I can push the experiment itself onto gitlab/ Pavlovia without a problem (e.g. using the sync command under the Pavlovia.org menu).

What did you try to make it work?:
I tried different ways of syncing. I first tried I tied it using the ‘Sync with web project’ button, which gave me the error below. I then tried syncing using the sync command under the Pavlovia.org menu - which worked fine - and then using “Export HTML”, at which point I got the same error message (below). I also tried using the Runner to “Run PsyhoJS task from Pavlovia” just for good measure, but of course, this doesn’t work because there is no HTML code to run. The html folder in the experiment directly is empty.

What specifically went wrong when you tried that?:
I get the following error message: PsychoPy encountered an unhandled internal error! Please send the report under “Details” to the developers with a description of what you were doing with the software when the error occurred.
Details:
Traceback (most recent call last):
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\app\builder\builder.py”, line 719, in fileExport
target=“PsychoJS”)
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\scripts\psyexpCompile.py”, line 73, in generateScript
compileScript(infile=exp, version=None, outfile=filename)
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:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment_experiment.py”, line 212, in writeScript
localDateTime, modular)
File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment\components\settings_init
.py", line 527, in writeInitCodeJS
self.prepareResourcesJS()
File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment\components\settings_init
.py", line 515, in prepareResourcesJS
resourceFiles = self.exp.getResourceFiles()
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment_experiment.py”, line 830, in getResourceFiles
condsPaths = findPathsInFile(params[‘conditionsFile’].val)
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment_experiment.py”, line 818, in findPathsInFile
for thisFile in findPathsInFile(val):
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment_experiment.py”, line 782, in findPathsInFile
filePath = eval(filePath)
File “”, line 0

^

SyntaxError: unexpected EOF while parsing

Thank you

Hi There,

So that we can pin down the issue, please can I check do you encounter this error when pushing another ‘dummy’ experiment to pavlovia or just this experiment?

Thanks,
Becca

Hi Becca, no I can push a dummy project without a problem, and JS is generating. In this one, I’m pretty sure the issue is that JS is not generating. Would it help if I provided the bits of custom python code in the projects and how they are being translated to JS?
Thanks

Hi There,

Aha yes that sounds like it could be the case - could you possible share the .psyexp file with us here so that your code components in context ?

Thanks,
Becca :slight_smile:

Hi Becca,
Yes, here it is: https://gitlab.pavlovia.org/cherkasovabbalab/reinforcementlearning
I made it public so you should be able to access it.
Thanks!
Mariya

Hi Becca, I don’t mean to pester you or anything like that - I just wanted to make sure you were able to access the experiment.
Thanks!
Mariya

Hi There, no - thanks for flagging. I actually still get a 404 error with the above link (but if the project is not loading to pavlovia I guess you cannot have a project to share? - in which case just the .psyexp file will be useful)

Thanks,
Becca

Hi Becca,
Here’s my .psyexp file. Thanks!
rl.psyexp (71.3 KB)

Hi there,

I think this is coming from your ‘response_code’ component in your ‘Trials’ routine.

Currently you import random on your python side and that import statement has been added to the .JS side (and imports don’t quite work that way in JS). Removing that line allows your experiment to compile to JS.

Random is actually imported automatically in psychopy, so you don’t need to import it. The problem then is that you won’t be able to use random.choice online as you can do locally. To fix that try this:

  1. remove the import random line from your code component as mentioned above.

  2. add a code component to your ‘instructions’ routine and set code type to be ‘JS’

add the following

choose = function choose(choices) {
  var index = Math.floor(Math.random() * choices.length);
  return choices[index];
}
  1. back in your response_code component, change code type to ‘both’.
  2. on the right hand side of this component, change any mention of random.choice to ‘choose’ (this will use your new JS function instead of trying to call the python method that won’t work online).

Let us know how you get on,
Becca

Hi Rebecca,
Thank you so much for your help! And it took me so long to try this out - crazy time of year. Unfortunately, this does not work. The experiment either isn’t using the choose function (or it doesn’t run correctly). Either way, it can’t seem to determine ‘condition’ - error message below when I try to sync with Pavlovia. I’ve tried putting the JS choice function in under ‘begin experiment’ and ‘before experiment’ - does not seem to make a difference. Also, the importing random in python in psychopy does appear to be necessar - the experiment does not run without it - but that makes no difference for the JS component evaluating condition. I’ve attached my file rl.psyexp file with the changes you suggested in case I made some mistake I just can’t spot.
Thanks again!
Mariya

Traceback (most recent call last):
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment_experiment.py”, line 782, in findPathsInFile
filePath = eval(filePath)
File “”, line 1, in
NameError: name ‘condition’ is not defined

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\app\builder\builder.py”, line 1221, in onPavloviaSync
self.fileExport(htmlPath=htmlPath)
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\app\builder\builder.py”, line 719, in fileExport
target=“PsychoJS”)
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\scripts\psyexpCompile.py”, line 73, in generateScript
compileScript(infile=exp, version=None, outfile=filename)
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:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment_experiment.py”, line 212, in writeScript
localDateTime, modular)
File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment\components\settings_init
.py", line 527, in writeInitCodeJS
self.prepareResourcesJS()
File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment\components\settings_init
.py", line 515, in prepareResourcesJS
resourceFiles = self.exp.getResourceFiles()
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment_experiment.py”, line 830, in getResourceFiles
condsPaths = findPathsInFile(params[‘conditionsFile’].val)
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment_experiment.py”, line 796, in findPathsInFile
files.extend(findPathsInFile(str(condFile)))
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment_experiment.py”, line 818, in findPathsInFile
for thisFile in findPathsInFile(val):
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment_experiment.py”, line 782, in findPathsInFile
filePath = eval(filePath)
File “”, line 0

^

SyntaxError: unexpected EOF while parsing

rl.psyexp (72.7 KB)

Hi There,

Sorry to hear you are still experiencing this difficulty.

I just downloaded your .psyexp file and pushed it to pavlovia without any error messages, perhaps this is a version issue - I notice that you are running 2020.2.4 - please could I check what happens if you upgrade to 2020.2.6 and try to sync then? https://github.com/psychopy/psychopy/releases

A couple of other things to note from checking out your psyexp file here:

  1. I notice that your ‘choose’ function is in the ‘Before Experiment tab’ - you might want to also move that to the ‘Before Experiment tab’ as you want to define the function at the start of the experiment rather than before the experiment starts :slight_smile:
  2. your ‘trials’ loop is expecting the variable ‘condition’ but I can’t see where in your experiment before the trials loop the variable ‘condition’ is created. Is it possible that you meant to add a code component to your instructions routine to set this, or add a field called ‘condition’ to your start gui (in which case you would want the conditions field of your ‘trials’ routine to read as $expInfo[‘conditions’]+.xlsx

Thanks,

Becca

Hi Rebeca,
This was partly a version issue - when I used a 2020.2.6 version, I was able to push to Pavlovia. Unfortunately, there is still no JS code being generated. There is no html folder on the remote, and the html folder on my local machine is empty. Based on the last_app_load.log, it looks like an issue with the name ‘condition’ not being defined, which is the output of the JS ‘choose’ function. Not sure if this has to do with the function or what you pointed out in your second point re the ‘condition’ variable. This variable is defined in the code component of the Trial routine, Begin experiment and yields the names of condition excel files before .xlsx. The Condition field in the Trials loop calls the $condition + .xlsx. This works just fine in psychopy to randomize my conditions. But perhaps it’s a problem in JS?
Thanks again,
Mariya