Installing PsychoPy on Linux (RHEL)

The official Linux installation documentation is woefully out of date.

This is the process I used to install PsychoPy 2022.2.4 on AlmaLinux 9. The below should work on any RHEL 9 compatible distro (Rocky, CentOS, Fedora), and uses a virtual environment to contain the installation. Using virtual environments supports multiple versions installed simultaneously, and makes it easy to remove them later by simply deleting the directory they are in.

version=2022.2.4

# Dependencies needed on my system - yours may differ:
sudo dnf install -y python3-tkinter git mesa-libGLU pcre2-utf32
sudo dnf config-manager --set-enabled crb # The CRB repo is needed for SWIG
# These packages are only needed for the installation, and can safely be removed afterwards:
sudo dnf install -y gcc-c++ swig python3-devel pulseaudio-libs-devel alsa-lib-devel wxGTK3-devel webkit2gtk3-devel

# Virtual environment for Python:
python3 -m venv psychopy-$version
. psychopy-$version/bin/activate
pip install --upgrade pip

# Install PsychoPy:
pip install attrdict wheel
pip install wxpython # This is super-slow to compile!
pip install psychopy==$version

# I use this to give priority without having to make any system-wide changes:
cp -p --remove-destination `readlink -f \`which python3\`` `which python3`
sudo setcap cap_sys_nice=eip `which python3`

# Now to run PsychoPy, use:
. psychopy-$version/bin/activate
psychopy &

Note: This is a follow-up to Installing PsychoPy 2022.1.4 on AlmaLinux 8.