| Reference | Downloads | Github

Error in importing .xlsx conditions file

Hello all,

I am having some problems with importing the .xlsx file that contains the conditions for my experiment. It seems that each time I alter the excel file in any way and re-save it, it breaks connection with PyschoPy. This is troublesome when working in the Builder but it is easy enough to simply reselect the file from the Trials menu. It becomes nearly impossible to deal with though when I’m working from the Coder window.

I should clarify that I have been building the basic outline for my experiment in the Builder and then having the Builder write the script - from there I am alter the code in the Coder window as I see fit to get the stimuli I need. The problem is that in the Coder window there seems to be no way to easily reestablish the connection with the .xlsx file if the connection is broken from altering the contents of the file. The pathway to the file is not changing at any point: I am saving the excel file with the same name and in the same location as it was previously. So it can be assumed that it is not a problem of the pathway being incorrectly written. It seems that whether I simply “save” the excel file or whether I “save as” with the same name and location the same problem presents itself.

Does anyone have any ideas about why the connection would be lost each time I alter the contents of the excel file and how I might be able to fix this?

Many thanks!

Hi Sarah,
I have no idea, but my experience with excel files is, you cannot reliably read them while they are opened in Microsoft Excel (or Libre Office etc.). Can you confirm that this problem persists if you close the file before running the code in Coder?


Hi Robin,

Thanks for your reply. I have taken your advice and tried running the experiment with the excel file closed and it does seem that this helps to resolve the problem.

Another point I should note for anyone looking at this forum with a similar issue is that, previously, I had my excel file in a folder that was titled “Vienna Experiment” (i.e. with a space in the folder name). Once I changed the folder name to “viennaExperiment”, the disconnection seemed to stop, at least up until this point. After speaking with some more experienced colleagues I realize that this is a particularly important point to watch for when programming in general.

One additional note: PsychoPy seems to create a default pathway for the excel file based on the location that the Coder script has been saved (i.e. if the script is saved to the Desktop then PsychoPy will assume the excel file is also in the Desktop folder). This is one more thing to check when experiencing trouble with importing the excel file from the Coder window.

Thanks again,

This is unlikely to be necessary. Keep working in Builder and insert code components within the Builder interface rather than attempting to edit the generated script. The code component will automatically insert the code at the right place (beginning of experiment, beginning of routine, every frame, etc) and allows you to keep tweaking the experiment using the GUI. Best of both worlds.

This is a feature rather than a bug. i.e. can you think of a better way that PsychoPy should search for your file? The alternative is to use a full absolute path to your file. You are still able to do this of course: PsychoPy doesn’t prevent you), but that creates potential for errors and makes your experiment non-portable.

Hi Michael,

Thanks for this reply - I wasn’t able to make sense of it right away but after some more time working with PsychoPy I can understand this better. The code component in particular is very helpful.