Hi everyone,
Ubuntu 22.04 comes with Python 3.10 and I could not - for the life of me - make it work with PsychoPy 2022.1.4. So, the “solution” I found was to install Python 3.9, since they seem to like each other.
First, let’s take care of the Python 3.9 part of the installation
Add software-properties-common so we can easily manage the repositories / PPA we are going to use.
sudo apt install -y software-properties-common
Install the deadsnakes PPA
sudo add-apt-repository ppa:deadsnakes/ppa
Update the package list
sudo apt update
Install Python 3.9 and some additional packages
sudo apt install -y python3.9 python3.9-venv python3.9-dev
Now, we can assing a priority to each of our Python versions (3.9 and 3.10) and set Python 3.9 as the default. A higher number means a higher priority - just to leave an explanation here, but this is not an essential step in this case, because I’ll show next how to manually enable a especific version system-wide.
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.9 2
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.10 1
To manually choose Python 3.9, type the corresponding number assigned to it and press enter after running the line below:
sudo update-alternatives --config python
Just to make sure, type python --version
into your terminal and check if Python 3.9 appears, indicating it is in use system-wide. As you can see, you can easily change it back to Python 3.10 if you need.
Now that we have our Python 3.9 installed, let’s move on
Install outdated psychopy from Ubuntu’s repository
sudo apt install psychopy
Install Psychopy dependencies and some packages needed to compile wxPython:
sudo apt install python3-pip make gcc libgtk-3-dev libgstreamer-gl1.0-0 python3-gst-1.0 libglib2.0-dev ubuntu-restricted-extras python-dev-is-python3 bison autoconf libtool-bin swig libpulse-dev libusb-1.0-0-dev portaudio19-dev libasound2-dev freeglut3 freeglut3-dev libgl1-mesa-dev libglu1-mesa-dev libgstreamer-plugins-base1.0-dev libgtk-3-dev libjpeg-dev libnotify-dev libsdl2-dev libsm-dev libtiff-dev libwebkit2gtk-4.0-dev libxtst-dev python3-testresources nodejs libsndfile1-dev libportmidi-dev liblo-dev curl
We will need to use pip to install packages specifically for Python 3.9. So, before installing anything using pip, we need this:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3.9 get-pip.py
To fix the PATH warnings, open .bashrc
file using gedit…
gedit .bashrc
… paste the line below at the end of it and save the file.
PATH=$PATH:$HOME/.local/bin
To avoid having to logout and back in again, run the line below for this alteration to take effect:
source ~/.bashrc
Now, compile wxPython to Python 3.9. This takes around 35 minutes in my core i7 5th gen machine - adjust your expectations accordingly
pip3.9 install -v --user --no-cache-dir --force-reinstall wxPython
Update psychopy using pip3.9
pip3.9 install psychopy -U
Raise the priority of the experiment process
sudo groupadd --force psychtoolbox
sudo usermod -a -G psychtoolbox $USER
Create a 99-psychopylimits.conf file using gedit:
sudo gedit /etc/security/limits.d/99-psychopylimits.conf
Paste in the following text to that file and save it:
@psychtoolbox - nice -20
@psychtoolbox - rtprio 50
@psychtoolbox - memlock unlimited
You may need to restart your computer before running Psychopy, but that is pretty much it
Downgrading to Python 3.9 is not exactly what I initially intended, but it works!
Have fun using PsychoPy 2022.1.4 in Ubuntu 22.04!
PS: I’ve spotted a little glitch in the window title bar when running PsychoPy using Wayland. It is not present in XOrg