Can't run psychtoolbox outside of stand-alone because of import psychtoolbox problem

TLDR: Can a developer please tell us what the situation is with the psychtoolbox import that is normally used by Psychopy’s sounds, and what alternative we might use?

Long version

On multiple Mac M-chip machines, we (Viplav Tuladhar, De-Wei Dai, and myself) are trying to run Psychopy using VSCode rather than through the Standalone IDE or Psychopy Studio. This problem does not seem to occur on Windows.

I will give the full setup/installation instructions below, but the result is that we get this error

ModuleNotFoundError: No module named ‘psychtoolbox’

when we execute the following two lines of code:

from psychopy import sound

highA = sound.Sound('A', octave=3, sampleRate=44100, secs=0.8, stereo=True)

The traceback reveals that psychtoolbox is needed by psychopy/hardware/speaker.py, as it includes

import psychtoolbox.audio as ptb 

This issue does not occur when using the standalone Psychopy builder and Coder, only when using an interpreter we have installed, which in our case we did in the following way:

conda create python=3.10 -n psychopy310
activate the environment using
conda activate psychopy310
and then use pip to install psychopy into that environment.
pip install psychopy

A somewhat-unsatisfactory workaround, we discovered, is to use psychopy_x86 through Rosetta rather than native on ARM, which we did by installing psychopy_x86 (python 3.10.18) with conda and attached it to Visual Studio Code as an interpreter. But that does work.

I see now that in November 2024, Jon wrote that Psychopy outside of standalone is impossible because of psychtoolbox not working. But we haven’t run into the tables/HDF problem, so perhaps it will work if we just avoid sound or use another sound library, right? We don’t need low-latency audio…

The tables/hdf5 issue has been resolved (those packages are now released with ARM support I believe). Mario has made ARM support ONLY as a part of his new pay-per-machine license for PTB 3.0.30 and I’m not clear that he’s even willing to provide this as an option* to the python community.

Going forwards (for the 2026.2 release in June) we’re moving away from PTB entirely because I’m not comfortable with this level of uncertainty about its future! But yes, while moving towards, this we’ve discovered various places where the code assumes PTB is present (i.e. it has annoyingly become a hard dependency).

What you need for now (what we do with Standalone/Studio) is install Intel python even though you’re on an ARM chip. It runs fine, just using Rosetta behind the scenes. A few ways you can achieve this (easiest first):

  1. Install PsychoPy Studio, and launch once, which will install a suitable python venv (one for each version of psychopy that you use) and all the necessary dependencies in ~/Library/Application Support/psychopy4/.python. Note that, unlike the issues that you used to have with packaged Python inside PyschoPyStandalone, Studio creates a regular Python venv and should do all you need. Also note that the psychopy lib installed this way doesn’t include the app code, or dependency on wxpython, because the Studio app itself is written in JavaScript!
  2. I think you can get uv to find/download/install an intel python if you call uv venv --python 3.11-x86_64. I haven’t tried that on a machine that /never/ had Python installed so I’m not 100% sure but it’s worth a try
  3. use a Universal (intel+ARM support) python installation and then tell your terminal to switch into intel arch to run it
  4. download an intel-only python (but then you may be limited what version was intel-only)

But, as I say, from the summer, we’ll be giving up on PTB entirely and allowing ARM-native python installations because PsychoPy itself is fine with that!

Best wishes,
Jon

* I’ve made repeated attempts to get in touch with Mario, and discuss solutions for how to work with him, but he hasn’t replied so eventually I gave up