How to install PsychoPy 2022.1.4 on Ubuntu 22.04

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 -o

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.


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 :wink:

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 :wink:

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 :slight_smile:


Thanks for sharing, I will certainly give it a go when time permits.

Wouldn’t it be simpler and cleaner to use an alternate Python version in a virtualenv? For one, you wouldn’t need to touch the system Python installation.

There are plenty of tools for managing Python versions and virtualenvs out there, such as pyenv, pyenv-virtualenv, python -m venv, conda, etc., with which it would be pretty straightforward to create an isolated environment with any Python version you want.

Unless there’s a good reason not to use virtualenvs, it’s probably best not to touch the system-wide Python version and packages.

TL;DR: I used pyenv to install a Python version separate from the system Python. The rest is not significantly different from OP.

Yesterday I successfully(?) installed PP on Ubuntu 22.04, and my method differs a little bit from yours so let me present it. You seem to have experience with installing PP so do let me know if you notice any problems.

The biggest difference is that I didn’t use or touch the system Python. As I mentioned, it’s best not to change that, because it may cause trouble with system packages that expect a particular version. On a machine solely used for PP this may not be an issue, but overall it’s a risk better to avoid. Also, it makes things simpler.

  1. Install pyenv; don’t forget the Python build dependencies

  2. Install Python 3.8.13 with pyenv, designate it as default python for current folder:

mkdir pp-build
cd pp-build
pyenv update
pyenv install 3.8.13
pyenv local 3.8.13 # this creates a file named .python-version

It’s not essential to create a new folder (here pp-build), the only reason I did so is because I’m changing the local default Python to another version, which creates a file named .python-version in the current folder. Having it in a new folder means it won’t have effect anywhere else.

I used Python 3.8 because that seems to be the recommended version. Haven’t tried other versions on 22.04 yet.

  1. Install base dependencies:

sudo apt install ubuntu-restricted-extras curl build-essential

These are essential packages often used not just for PP. (I admit the grouping of dependencies in points 3-5 is somewhat arbitrary.)

  1. Install PP
sudo apt install swig libpulse-dev libasound2-dev # for pocketsphinx
python -m pip install -U pip setuptools wheel # update basic tools for building and installation
pip install psychopy # should compile at this point

During the process, pip compiles packages into wheels, which are cached and can be used for later installations. This is handy if one wants to purge this build environment later in order to install PP into a clean one. The wheels won’t need to be rebuilt.

  1. Install wxpython
sudo apt install libtiff-dev libjpeg-dev libgtk-3-dev freeglut3 freeglut3-dev \
  libwebkit2gtk-4.0-dev libsdl2-dev libsecret-1-dev libnotify-dev \
  libgstreamer-plugins-base1.0-dev gettext make libglib2.0-dev
pip install wxpython # should compile

Once wxpython wheels become available for Ubuntu 22.04, this step will be reduced to downloading and installing that wheel (descibed here).

Some of the above packages have newer versions, e.g. libgtk-4-dev and libwebkit2gtk-4.1-dev, that didn’t work well for wxpython.

  1. Install psychtoolbox (has wheel, already installed)

The documentation says it’s necessary to compile psychtoolbox as well, but this is probably outdated as PTB has manylinux wheels that was already installed as a PP dependency in step 4 without any issues.

  1. Priority & security limits

See @bastosfh’s original post above.

  1. Cleanup?

At this point, I’d probably delete the entire Python 3.8.13 installation and reinstall it, then create a virtualenv specifically for PP. As the dependencies are already built, they can be installed again from wheels and won’t need dependencies (needs to be tested).

It might be also OK do remove (most of) the apt packages that are only required for building.

  1. Enjoy?

So, I was able to successfully install psychopy and wxpython, but I haven’t tested if everything worked well. Opening a window and visual stimuli seem to work, but I haven’t tested audio, input, movie etc. yet. Builder and Coder launched, but I’ve never used them so can’t test if everything is OK.

Psychopy may have other dependencies that I didn’t consider, and if those need to be compiled, that’s of course best done before cleaning out the build environment.

  1. Discussion (feedback is appreciated)
  • I think the list of apt packages in OP by @bastosfh could be trimmed a bit. Some of them were already auto installed on Ubuntu either by default or as a dependency of one of the other packages:
    gcc libgstreamer-gl1.0-0 libgl1-mesa-dev libglu1-mesa-dev libsm-dev libxtst-dev.

  • Some, I think, used to be required for psychtoolbox, but now that it has a wheel, not needed:
    libusb-1.0-0-dev portaudio19-dev.

  • Others, I don’t know. The packages compiled without errors, but it’s possible that it would be better to have some of these dependencies? wxpython, in particular, skips some missing packages and only issues warnings that don’t appear unless the build fails, which means some functionality may be disabled. I wonder which of these packages I should’ve installed:
    python3-pip python3-gst-1.0 python3-testresources python-dev-is-python3 bison autoconf libtool-bin libsndfile1-dev libportmidi-dev liblo-dev nodejs
    Pip is one I guess is only needed for the system Python. Other dev packages are probably required by some build process, but their absence didn’t cause any errors. I’m assuming they aren’t required for runtime.

  • Full PP functionality likely requires other dependencies, e.g. VLC, FFMPEG that I haven’t bothered to install and test.

  • As you may have noticed, I did not use a virtualenv for the initial build process. The reason for this is that virtualenvs (at least those generated by pyenv virtualenv) are missing essential components required to build wxpython (e.g. python-config and header files). This means that the installation of 3.8.13 isn’t pure anymore and any application using that would be affected. However, this is only temporary because once the wheels are built for the dependencies, it’s possible to delete and reinstall this version of Python, and then use a virtualenv. A bit inconvenient, but only requires a few extra steps.


Thanks for this thread, the official Linux installation documentation is indeed woefully out of date.

I am using Python 3.9 on AlmaLinux 8, so the below should work on any RHEL 8 compatible distro (Rocky, CentOS, etc). I am also using a virtual environment, as above.


# Dependencies needed on my system - yours may differ:
sudo dnf install -y gcc-c++ swig python39-devel pulseaudio-libs-devel alsa-lib-devel wxGTK3-devel webkit2gtk3-devel
# These packages are only needed for the installation, and can safely be removed afterwards, except for python39.

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

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

# 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 --builder &
1 Like

Hi @kxKkPbRawwdwEu

You are right about been safer to avoid touching Python’s default installation in case someone is not installing PsychoPy in a machine exclusively dedicated to running it. Thanks for leaving a description of how to install and configure pyenv above.

Also, thanks for pointing out that the list of packages I reported may be trimmed down a bit. Some of them may have been necessary when I was trying to make PsychoPy work with Python 3.10, but are not needed in an Ubuntu’s clean install and Python 3.8.

As soon as I can, I’ll try to replicate your steps using Python 3.9 and will report it here with further tests of Builder.

Best regards,

Here is the link to instructions on how to install PsychoPy on Ubuntu 22.04 using virtualenv (i.e. without touching python’s system installation).

Also, I’ve indicated needed packages more thoroughly this time, for documentation purposes.

So, I have been struggling with the webkitgtk issues (hard to find libwebkitgtk-1.0 anymore). As a result, I use older packages/OS to keep psychopy working with libwebkitgtk-1.0, and that is getting burdensome. Do these installation instructions avoid the webkitgtk issues? Thx.

Does anyone have an anaconda version of Linux/Ubuntu installation? I think of anaconda as kind of a virtual environment.

Hi @jeff

It’s been a while since I installed PsychoPy using Anaconda…

Nevertheless, I’ve described here how to install PsychoPy using virtualenv. I have no reason to suspect that the steps should be much different.

The only issue I could not solve is that I can’t use Builder to sync to Gitlab / Pavlovia.
Besides that, I’ve been using Psychopy Builder without any problems.

I hope that helps :slight_smile:

Try with libwebkit2gtk-4.0-dev, it worked for both OP and me. … unless I’m mistaken about why you’re using the package.


@bastosfh’s instructions should work for you provided you only use conda to create the virtual environment, and use pip from then on. Packages on conda can be different from those on pypi, so the recipe here might not work.

Best of luck and do post your findings here if you succeed with conda packages.

This is resulting in an error for me.
# Sub-process /usr/bin/dpkg returned an error code (1)

I recently did this using miniconda, and these are the steps that worked for me.

  1. Install miniconda
  2. Create a new virtual environment
  3. Get a wxPython wheel from Index of /wxPython4/extras/linux/gtk3 and install it
  4. Install psychopy and psychopy-sounddevice
  5. Update libstdc++
    Like this:
conda create -n psychopy python=3.8
conda activate psychopy
pip install wxPython-4.2.0-cp38-cp38-linux_x86_64.whl
pip install psychopy
pip install psychopy-sounddevice
conda install -c conda-forge libstdcxx-ng

Then run with

conda activate psychopy

I haven’t done much besides run the stroop demo, but it appears to work fine.

1 Like