# ReferenceError: infile is not defined

**URL:** <https://discourse.psychopy.org/t/referenceerror-infile-is-not-defined/36993>\
**Category:** Online experiments\
**Tags:** eyetracking, pavlovia\
**Created:** [October 22, 2023, 6:58pm UTC](https://discourse.psychopy.org/t/referenceerror-infile-is-not-defined/36993 "2023-10-22T18:58:28Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![fmtoma](https://avatars.discourse-cdn.com/v4/letter/f/58f4c7/32.png) [@fmtoma](https://discourse.psychopy.org/u/fmtoma)\
**Post date:** [October 22, 2023, 6:58pm UTC](https://discourse.psychopy.org/t/referenceerror-infile-is-not-defined/36993/1 "2023-10-22T18:58:28Z")

</div>

URL of experiment:  
[https://run.pavlovia.org/fmtoma/faces\_wm](https://run.pavlovia.org/fmtoma/faces_wm)

> **[Pavlovia](https://pavlovia.org/fmtoma/faces_wm)**
>
> The place for the wide community of researchers in the behavioural sciences to run, share, and explore experiments online

Description of the problem:

I copied a version of the experiment that used to work in the past and I had to restructure some routines.

In the Before experiment that of a routine that initializes files with some images in the beginning, I have the following:

```auto
import random, xlrd
import numpy as np

# randomize the seed
# random.seed()

# dot counting stimulus list
infile = 'stimulus_list/image_names.xlsx'

# one_back stimulus list
one_back_file = 'stimulus_list/Routine_1_Data.xlsx'

# two_back stimulus list
two_back_file = 'stimulus_list/Routine_2_Data.xlsx'

# three_back stimulus list
three_back_file = 'stimulus_list/Routine_3_Data.xlsx'

```

This translates to the js file perfectly. However, I get the following error message:  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/7/0/7087a06414045ac71243128004cc232c46a7f9da.png)

I checked online and all the files are in the “stimulus\_list” sub-folder.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/1/c/1c29f2886550ce84b5c08c0293e6949a3bb06c2c.png)

This is how the JS code looks like:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/2/7/27acc2a122adb6c23ad000f0ddd651db617e3f68.png)

Any ideas?  
Thanks.

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [October 22, 2023, 10:25pm UTC](https://discourse.psychopy.org/t/referenceerror-infile-is-not-defined/36993/2 "2023-10-22T22:25:44Z")

</div>

Try putting it in Begin Experiment instead of Before.

I assume you know that those imports won’t work online.

---

<div class="post-metadata">

**Author:** ![fmtoma](https://avatars.discourse-cdn.com/v4/letter/f/58f4c7/32.png) [@fmtoma](https://discourse.psychopy.org/u/fmtoma)\
**Post date:** [October 23, 2023, 7:52pm UTC](https://discourse.psychopy.org/t/referenceerror-infile-is-not-defined/36993/3 "2023-10-23T19:52:44Z")

</div>

I tried changing it to “Begin Experiment” and it still doesn’t work.

I get the same error.

Any other idea?

---

<div class="post-metadata">

**Author:** ![fmtoma](https://avatars.discourse-cdn.com/v4/letter/f/58f4c7/32.png) [@fmtoma](https://discourse.psychopy.org/u/fmtoma)\
**Post date:** [October 25, 2023, 6:30pm UTC](https://discourse.psychopy.org/t/referenceerror-infile-is-not-defined/36993/4 "2023-10-25T18:30:55Z")

</div>

@wakecarter I’ve tried re-doing the project, changing "'" to “/”, changing from piloting to not active and vice versa and still I have the same error.

Any idea on why this doesn’t work?

It worked in the past.

Would this have something to do with the fact that it’s a Save as from the previous experiment that worked?

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [October 25, 2023, 10:03pm UTC](https://discourse.psychopy.org/t/referenceerror-infile-is-not-defined/36993/5 "2023-10-25T22:03:31Z")

</div>

In your Builder code components is there still a tab somewhere that says Syntax Error Fix Python code?

Use Auto translate code components wherever possible. If you need to add something just for Python or JS then switch it to Py, JS or Both.

---

<div class="post-metadata">

**Author:** ![fmtoma](https://avatars.discourse-cdn.com/v4/letter/f/58f4c7/32.png) [@fmtoma](https://discourse.psychopy.org/u/fmtoma)\
**Post date:** [October 25, 2023, 11:22pm UTC](https://discourse.psychopy.org/t/referenceerror-infile-is-not-defined/36993/6 "2023-10-25T23:22:36Z")

</div>

There isn’t any error for Syntax Error Fix Python code in the code component that defines “infile”.

There was for an eye-tracking component, but I disabled that component and I re-compiled.

I also have components that are only Py.

But if the components that are with errors or only “Py” are defined after I define “infile”, then it shouldn’t matter, as “infile” is defined before.

I still get the same error.

Thanks,  
Mihai

---

<div class="post-metadata">

**Author:** ![fmtoma](https://avatars.discourse-cdn.com/v4/letter/f/58f4c7/32.png) [@fmtoma](https://discourse.psychopy.org/u/fmtoma)\
**Post date:** [October 26, 2023, 12:21am UTC](https://discourse.psychopy.org/t/referenceerror-infile-is-not-defined/36993/7 "2023-10-26T00:21:33Z")

</div>

I managed to solve this by commenting all lines - I won’t use that part in the online experiment anymore.

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [October 26, 2023, 8:04am UTC](https://discourse.psychopy.org/t/referenceerror-infile-is-not-defined/36993/8 "2023-10-26T08:04:47Z")

</div>

> [@fmtoma](#):
>
> `infile = 'stimulus_list/image_names.xlsx'`

Okay – though it’s definitely possible to use code link this if you put it on the Python side of an Auto translate code component. It may lead to a resource not found error if you haven’t added the spreadsheets via Experiment Settings / Online or a Resource Manager component, but that’s a different error.
