Traceback error cannot import 'layout'

Hello,

I am trying to install my experiment to all of out participant running computer and am running into a problem on some of them. When I try to open the experiment from the python file, I get the error message below. If I open the experiment in the builder, and then run, it works. If I click compile to python script and then run, it works. But when I save the compiled script and then run from the .py file, that is when I get the error message and the black window closes out. Any ideas?

image

It’s most likely that the version of PsychoPy installed as a Python package is behind the version installed via the standalone installer - so when you run the Python file it doesn’t recognise the layout module (which was only added in the last few years), how are you running the Python file? Via commands or by right clicking and going “run with Python”?

I installed the newest version of psychopy on all of the laptops. So it’s odd that it’s not a problem for most of the laptops, but is for 3.
I set it to open with python then double click. The black box appears, it shows the hello message. Then the error message and exits.

But did you install the latest version via the standalone installer, or via something like pip or conda?

I downloaded the standalone installer.

The standalone installer won’t affect previously installed Python environments, as if it did installing PsychoPy could break other Python-based software. What you need to do is update the version of the module PsychoPy (not the software) installed on the laptop.

First you’ll need to find the location of the Python executable they’re running, to do this make a python file whose contents is:

import sys
print(sys.executable)

and run it in the same way you were running those experiments. It’ll print the location of the python.exe file in the output window that pops up.

Once you’ve got this, you can do this in the system terminal:

"path/you/just/copied/python.exe" -m pip install psychopy --upgrade

And it’ll update the version of PsychoPy installed on the specific Python environment where .py files are being run on that laptop

Hello,

Thanks for your response.
I think I have done it correctly. But when I try to do the install in the terminal nothing happens? Is something supposed to happen?
I am not at all familar with using the command prompt, I only ever use the builder to make experiments.
I also notice some of the experiments I have do run normally, and others give the error message in the original post.

Might be you need to target python.exe rather than pythonw.exe? It should be in the same folder so you can just remove the w from the filename.

If it differs between experiments, that’s most likely due to the use version setting - if an experiment is set to use an older version, it won’t find layout even if the newer version is installed

So I was able to get it to work. However, I still get error messages like: AttributeError: ‘NoneType’ object has no attribute ‘close’

**Edit: I needed to also update pip (I don’t actually know what any of that means but I had a message in the command prop to add pip to the end of the code you suggested and now everything appears to be working! Thank you so much for your help I really appreciate it!