Skip to content

Latest commit

 

History

History
244 lines (169 loc) · 9.06 KB

v2024.2.1.md

File metadata and controls

244 lines (169 loc) · 9.06 KB

PsychoPy on Apple Silicon Macs

The current version of PsychoPy runs on Apple Silicon (e.g. M1, M2, and later) Macs through Rosetta 2. Below are instructions to run a native Apple Silicon (arm64) version of PsychoPy.

1. Install native Python for Apple Silicon Macs

Install brew to install various apps needed for PsychoPy.

brew install [email protected]

Python 3.10.14 (19 Mar 2024).

2. Clone repository

git clone https://github.com/waltervanheuven/psychopy-on-M1.git
cd psychopy-on-M1

3. Create virtual environment with Python 3.10

python3.10 -m venv venv

# activate venv
source venv/bin/activate

# update pip, setuptools, and wheel
pip install --upgrade pip setuptools wheel

4. Install main dependencies

pip install -r requirements.txt

5. Install PyQt6

Install PyQt6 version 6.7.1

pip install PyQt6

6. Install tables

tables version: 3.10.2.dev0

Using latest development version to avoid compiling issues.

brew install hdf5 c-blosc lzo bzip2
export HDF5_DIR="$(brew --prefix hdf5)"
export BLOSC_DIR="$(brew --prefix c-blosc)"
export LZO_DIR="$(brew --prefix lzo)"
export BZIP2_DIR="$(brew --prefix bzip2)"

pip install git+https://github.com/PyTables/PyTables

Note: opt folder of homebrew for Apple silicon is located in /opt/homebrew/. On Intel macs it is located in /usr/local/. To find correct path on both architectures use brew: $(brew --prefix ....).

7. Install Psychtoolbox

psychtoolbox version: 3.0.19.14

pip install git+https://github.com/Psychtoolbox-3/[email protected]

8. Install wxPython

wxPython version: 4.2.1

export CFLAGS="-I/$(brew --prefix)/include"
export CXXFLAGS="-I/$(brew --prefix)/include"
pip install wxPython

9. Install ffmpeg

brew install ffmpeg

10. Install Psychopy

Using PsychoPy source.

mkdir tmp
cd tmp
wget https://github.com/psychopy/psychopy/archive/refs/tags/2024.2.1.zip
unzip 2024.2.1.zip

# replace pyproject.toml with amended version:
#   - disabled setuptools because latest version already installed in venv
#   - downgraded python-bidi from 0.5.0 to 0.4.2 so that Preference window works
#   - disabled PyQt6 because already installed in venv
#   - disabled psychtoolbox because already installed in venv
#   - disabled tables because already installed in venv
#   - disabled wxPython because already installed in venv
cd ..
cp pyproject.toml tmp/psychopy-2024.2.1/

cd tmp/psychopy-2024.2.1
python3 -m pip install .
cd ../..

11. Install pyo plugin

pip install psychopy-pyo

12. start PsychoPy

psychopy

Please note that PsychoPy fails to start without any error message appearing in the Terminal when Secure Keyboard Entry is enabled in the Terminal. Make sure this is turned off.

Remaing issues and possible errors and solutions

  • Psychtoolbox (PTB) import issue

PsychHID.cpython-310-darwin.so is an Intel library. There is not yet an Apple Silicon version of this library. Therefore, importing psychtoolbox fails.

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".../venv/lib/python3.10/site-packages/psychtoolbox/__init__.py", line 28, in <module>
    from .PsychHID import PsychHID
ImportError: dlopen(.../venv/lib/python3.10/site-packages/psychtoolbox/PsychHID.cpython-310-darwin.so, 0x0002): symbol not found in flat namespace '_libusb_bulk_transfer'

Event module is therefore used for the keyboard component.

  • Microphone component is not working

    Microphone component fails because Psychtoolbox import fails.

  • If timeByFramesEx.py fails to run, change line 34 to matplotlib.use('QtAgg').

    Note that there is vsync OpenGL bug in macOS Ventura/Sonoma so vsync doesn't work correctly.

  • Eyetracker components not working

    Unable to install tobii-research because there is not yet Apple Silicon support for the Tobii Eyetrackers Python library.

  • PsychoPy fails to start again after exiting PsychoPy

    Issue might be due to sandboxing. Fix this by installing the Intel (Rosetta 2) version of PsychoPy 2024.2.1 and starting this up once before trying again the Apple Silicon version.

    If this still fails, uncheck "Secure Keyboard Entry" in the Terminal / iTerm2.

  • Unable to revert mtime: /Library/Fonts error

    Fix this by installing libmagic.

    brew install libmagic
  • Drivers for Apple Silicon Macs

  • Error when creating wheels (e.g. gevent)

    Could be an issue with a beta version of xcode tools installed on your Mac. Revert back to latest (non-beta) version.

    sudo rm -rf /Library/Developer/CommandLineTools
    xcode-select --install
  • Other issues

    For other issues it might help to clear the pip cache.

    pip cache purge

If PsychoPy fails to start up after you have changed the preferences, remove the file userPrefs.cfg.

rm ~/.psychopy3/userPrefs.cfg

Status

Benchmark wizard report (14" M1 Max MacBook Pro, macOS 14.6.1).

Previous version results:

PsychoPy
PsychoPy 2024.2.1
locale None.UTF-8
python version 3.10.14 (64bit)
wx 4.2.1 osx-cocoa (phoenix) wxWidgets 3.2.2.1
pyglet 1.5.27
rush True
Visual
openGL version 2.1 Metal 88.1
openGL vendor Apple
screen size 3024 x 1964
have shaders True
visual sync (refresh) 7.28 ms 1
refresh stability (SD) 5.41 ms 1
dropped frames 75 / 181 1
openGL max vertices 1048575
GL_ARB_multitexture True
GL_EXT_framebuffer_object True
GL_ARB_fragment_program True
GL_ARB_shader_objects True
GL_ARB_vertex_shader True
GL_ARB_texture_float True
GL_ARB_texture_non_power_of_two True
Numeric
numpy 1.26.4
scipy 1.14.1
matplotlib 3.9.2
System
platform darwin 14.6.1 arm64
CPU speed test 0.003 s

1 There is a vsync OpenGL issue on macOS Ventura/Sonoma.

Result of running timeByFramesEx.py (60Hz LCD screen of M1 MacBook Pro, expected mean = 16.67 ms):

Figure_1_ventura

Note that vsync is working fine with PsychoPy in macOS Monterey 12.6.X (no dropped frames and stable vsync). Furthermore, you can run macOS virtualized using VirtualBuddy on Apple Silicon. Running a virtualized macOS works very well and the frame rate in PsychoPy is then stable.