Adapting experiment from PsychoPy 1.8 to PsychoPy 3 for Psychology Undergraduate Lab

Hi! Together with others, I teach a Cognition Lab for undergraduates. Till now we have stubbornly kept using PsychoPy 1.82, because we had a small library of experiments that was working with that version. Now with Catalina that version of PsychoPy is no longer usable and we are in trouble (by the way, personally I am still using MacOs Mojave.)

From now on, as you read, please forgive my ignorance and be patient. It is my understanding that the main difference between the previous version of PsychoPy and PsychoPy 3 is that the latter runs Python 3. Is that the only difference or are there other ones? I have taken one of our files (the line length experiment - see attachment for the old version) and I have tried to convert it to python 3 using an online converter. Then I have tried to run it in PsychoPy 3 but I get the following message:

####### Running: /Users/serena/Dropbox/_CogLabs/Spring 2020/trial2to3.py #######
2020-01-30 14:26:32.247 python[52083:1835832] ApplePersistenceIgnoreState: Existing state will not be touched. New state will be written to (null)
Traceback (most recent call last):
File “/Users/serena/Dropbox/_CogLabs/Spring 2020/trial2to3.py”, line 5, in
import xlwt
ModuleNotFoundError: No module named ‘xlwt’

Then, in the terminal, I have:

  1. switched to Python 3 on my Mac

nbp-25-133-222:OpenBUGS323 s $ python --version
Python 3.8.0

  1. installed xlwt and checked it was installed with Python 3.8:

nbp-25-133-222:OpenBUGS323 s $ python3.8 -m pip install xlwt
Requirement already satisfied: xlwt in /Users/serena/.pyenv/versions/3.8.0/lib/python3.8/site-packages (1.3.0)

But I always get the same error message.
How can I get around the error? More in general, what’s the best way to translate our old experiment to PsychoPy 3?

Thank you!

No, that is just kind of a coincidence. PsychoPy 3 has been released running under both Python 2 and 3 (although I think the Python 2 version for Mac might no longer be released). The main change in PsychoPy 3 is proper support for running studies online.

But in general, yes, converting scripts to Python 3 is good anyway (as Python 2 is finally retiring) and it is necessary on a Mac already.

So far, I think your issue is not really about Python 3 per se. The key thing is about getting xlwt installed in the right place, or (probably better), using another library that gives you similar functionality.

It seems to be installed in your Python 3.8 installation, but you don’t say where you are running PsychoPy from. Is it from the standalone app? If so, it doesn’t have access to whatever you install in another Python installation (it bundles its own Python and dependencies).

So if you need xlwt, it needs to be installed in the same version of Python that is running your psychoPy script.

But given previous discussions, is it needed at all? Could you just be writing .xlsx files, or (even better), .csv, and avoid the need for this library altogether?

Hi Michael,

Thanks a lot for your answer. Since all the previous versions of PsychoPy are on Github could you (or someone else) let me know which one is the latest Mac 32bit version that runs on Python2? It could be helpful for the transition.

You are right, I did not mention were I was running PsychoPy from. Yes, its from the standalone app.
Do you know how I can see which version of python is running it? Unfortunately I don’t know how to modify the file in the way you suggested, and I’d rather have the file running the xlwt library, but I appreciate your suggestion.

Thank you,
Serena

Switch to the Coder view, and in the “Shell” tab, if you scroll up, you might see the Python version listed there. If not, type:

import sys
sys.version

Scrolling through the list of releases at Releases · psychopy/psychopy · GitHub, it looks like the latest might have been PychoPy3 Beta 7:

but we wouldn’t recommend running that - it was a beta after all, at a point when the software as being rapidly released to deal with issues. If you are making transition, it really would be best to go to Python 3 - you’re just delaying another transition later. And as mentioned, the xlwt issue is not necessarily Python 3-related anyway.

I think your best option would be to update to the current PsychoPy 3 standalone app, and tell it how to link to the xlwt library externally:

https://www.psychopy.org/recipes/addCustomModules.html