Uploading online error

I am trying to run an experiment I created on the builder view on Pavlovia.
And I get the following error:

Unfortunately we encountered the following error:

  • ReferenceError: Can’t find variable: os

Try to run the experiment again. If the error persists, contact the experiment designer.

Does that refer to:

import os # handy system and path functions

I noticed from the coder view that this was imported by builder at the beginning of my experiment.

Thank you

So you didn’t add it yourself? Have you called anything os in your experiment?

No i have not called a variable os. The only ‘os’ I can find when I look in the python script generated is this:

import os # handy system and path functions

which is then called in at different places in the script eg:

Ensure that relative paths start from the same directory as this script

_thisDir = os.path.dirname(os.path.abspath(file))

I did not import this myself in any code component of the builder view. I guess is was put automatically from some choices i made on the builder.

This is the online category. Does os appear in your javascript file?

No, i have checked the java script and i can not find anything named os.

Does the fact that i can not find a variable named os on the java script mean, the problem comes from the os import on the python script? Should I find a replacement of that?

Do you have your experiment settings set to an old PsychoPy version?

Apologies i have just spotted these os in my java script. Is this relevant? These are some examples:

expInfo[‘OS’] = window.navigator.platform;

img_files = function () {
var _pj_a = [], _pj_b = os.listdir(img_dir);

My Psychopy version is 2021.1.0.

There are more recent ones of 2021.1.2 and 2021.1.4 should I choose any one of those?

Thank you

I tried version 2021.1.4 but it did not fix the problem.

1 Like

I think I found the lines where the problem is in the javascript:

var _pj_a = [], _pj_b = os.listdir(img_dir);
_pj_a.push(os.path.join(img_dir, i));

It does not recognise what the os is here. This is because there is no ‘import os’ or something similar at the beginning of my JS just as there is an import os at the beginning of the python script.

Is there an os for JS which I have to put at the beginning of the script and if yes what is the exact structure?

Or I need to change the commants of listdir and path.join?

Thank you

Tell me more about your image files. Are you accidentally trying to load them from your local computer?

The directory for the image files is the following:

img_dir = “./stimuli/transparent”;

These are two folders which are within the bigger folder where the psyexp file also is.

I have included this code at the beginning of the experiment:

img_dir = ‘./stimuli/transparent’

get image file path

img_files = [os.path.join(img_dir,i) for i in os.listdir(img_dir) if i.endswith(’.jpg’)]

choice three targets and no target randomly


0-2 are targets and 3 is no target

expInfo[‘par_targets_list’] = img_files[:4]

from third file onwards: distractor

expInfo[‘distractors’] = img_files[4:]

Did you add this code? It looks like it is supposed to create the image list by looking at the folder. This won’t work online. The easiest option is to use a spreadsheet.

Yes i added this code because the selection of the images i want is quite complicated. So from a subset of 11 image files I want the programme to randomly select 3 different ones for each participant. These three will be the targets and the rest will be the distractors in the visual search task. But for every participant, three different targets need to be chosen.

How can I do this using a spreadsheet? or a code part that will work online?

Have a look at my interleaved lists code snippet and Brookes template experiment for information on how to preload the contents of an Excel file into a list so you can use it in a later loop.

Thank you for sending that over I am looking at it right now. So what do the fillers refer to in this case:?

how to insert items from a list of targets at spaced intervals within a list of fillers.

Based on my understanding of your design you probably want to load all of your items as fillers and then slice it into one list of targets and one of fillers. Alternatively, you could simply append the first 3 items to the targets list and then the following 8 to fillers (based on a loopIdx counter)