Pygame not present in psychoPy 2020.2.4 on MacOS?

OS (e.g. Win10): MacOS 10.15.6
PsychoPy version (e.g. 1.84.x): 2020.2.4
Standard Standalone? (y/n) y

I have a working psychopy experiment which I wanted to run with pygame as the audio engine. I changed this in Settings–> Audio, saved, exported to runner, and tried to run.

Now, I get this error message in the Stdout window on starting the experiment:

0.4158     WARNING     pygame audio lib was requested but not loaded: ModuleNotFoundError("No module named 'pygame'",)
Traceback (most recent call last):
  File "PATH/exp_lastrun.py", line 19, in <module>
    from psychopy import sound, gui, visual, core, data, event, logging, clock
  File "/Applications/PsychoPy.app/Contents/Resources/lib/python3.6/psychopy/sound/__init__.py", line 102, in <module>
    .format(prefs.hardware['audioLib']))
psychopy.exceptions.DependencyError: No sound libs could be loaded. Tried: ['pygame']
Check whether the necessary sound libs are installed
##### Experiment ended. #####

Is there a way to install pygame, or should it be packaged with the download?

It should be yes, however you can also install Pygame manually!

As a habitual Windows user I’ll defer to @jon on this one - I could certainly walk you through installing a package using the Windows command prompt and I believe it’s pretty similar on Mac, but I don’t want to give any advice I can’t test myself.

Yes, the issue here was code signing. Mac really demands signing of apps now and blocks apps that aren’t fully signed and “notarized” which is why there were so many problems getting PsychoPy to run at all on the mac recently.
The version of pygame I had on my mac refused to code-sign because they were using SDL libs that are compiled on old versions of the mac SDK (I think is the reason). I wasn’t able to fix that issue quickly - I believe I need to install a “dev” version of pygame 2.0.0 to get more recent binaries but that will need testing to make sure nothing breaks

Workaround1 : use a different sound engine. Pygame has pretty much the worst timing of all the options. Is there a reason you need it?

Workaround 2: you should be able to get pygame working by installing it to another python3 installation on your system and then pointing PsychoPy preference for additional libs to include that folder

Thanks @jon for all your work to make PsychoPy Mac-friendly, I’m sure it’s not easy but I really appreciate being able to run it!

I had originally posted this because I was trying to see if different sound engines would fix the problem in this thread (still unresolved). But from the looks of it, sound engine is not the problem.

I know Jon is a busy guy, so I don’t want to bother him too much. But could anyone here explain how to do workaround 2 at an idiot proof level? Thanks!

1 Like

Second this

To get pygame on Big Sur I think the steps would be:

  • install Python 3.6 from Python.org e.g. Python Release Python 3.6.7 | Python.org
  • install pygame for that python install with something like : /Library/Frameworks/Python.framework/Versions/3.6/Python -m pip install pygame
  • Find the path to that package (eg. /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages) and add that to your PsychoPy prefs somethign like this:

Hopefully then import PsychoPy (before import pygame) will now find your pygame installation in that site packages folder

1 Like

Hi there! I have been troubleshooting this issue for a week and have tried to implement workaround 2 as described.

We had been trying to use the most recent version of standalone Psychopy, but I downloaded Python 3.10.6 as well and successfully installed Pygame. I just can’t figure out how to “point Psychopy preference for additional libs to include that folder.” Screenshot of what I have tried attached (I have tried both 3.10 and 3.10.6 in the file path). The error remains the same (“psychopy.exceptions.DependencyError: No sound libs could be loaded. Tried: [‘pygame’]
Check whether the necessary sound libs are installed”)

Thanks!

When you’ve added the path you’ve ended up beginning with “./” but that “.” means starting with the current folder. Unless you know that the current folder is the place where your script is starting that’s likely to be a bad idea. You want to know the absolute path to the pygame lib.

Also though:

  • The issue is solved in that the most recent release (2022.2.4) does include the pygame lib for you
  • I would strongly suggest you allow PsychoPy to use one of the higher-performance by setting your AudioLib setting to include SoundDevice and/or PTB

edit: sorry, I went and checked and 2022.2.4 does not include pygame still because of the pygame libs not being compatible with MacOS gatekeeper code-signing restrictions