Is there a Docker image for PsychoPy?

Dear PsychoPy team,

In my (admittedly) limited experience with PsychoPy, I am getting the impression that it does not play very nice with Ubuntu. I read suggestions that it runs fine on a VM. This seems like a massive overkill to me. I was under the impression that VMs were pretty much superseded by Docker these days, right?

So, is it possible to run PsychoPy on Ubuntu using Docker? If this is indeed possible, I would very much appreciate instructions on how to achieve this.


1 Like

We’ve been working to improve Ubuntu support in the 2022.1 release (imminent) but there are a few documents to help get you started on that e.g. Installation headaches and (partly) fixes on Ubuntu 20.04 - #6 by Axel

I would definitely advise against using a VM to run experiments due to performance issues. A Docker image is an interesting idea as a way to provide a ready-to-go installation for ubuntu. We’ll look into it

Dear Jon,

Thanks. That sounds very encouraging and absolutely wonderful! It would cool to have PsychoPy run a little more smoothly on these systems as well.



I dabbled with Docker for a bit over the weekend. I noticed that there were some images that sound like they would allow you to run PsychoPy. So I tried this one here. Unfortunately, I could not get it to run.

Because of that (and as a bit of a Docker exercise) I decided to write my own Dockerfile. It looks like this:

FROM ubuntu:20.04

# Installing psychtoolbox requires specifying the local time zone. This 
# cannot be done interactively when building the image. Need to find a
# way to first set a default time zone.
# See
RUN apt-get update && \
    apt-get install -yq tzdata && \
    ln -fs /usr/share/zoneinfo/Europe/Kiev /etc/localtime && \
    dpkg-reconfigure -f noninteractive tzdata

RUN apt-get install -y python3-pip wget

RUN pip3 install psychopy
RUN wget
RUN pip3 install wxPython-4.1.0-cp38-cp38-linux_x86_64.whl
RUN apt-get install -y libusb-1.0-0-dev portaudio19-dev libasound2-dev 

# When trying to start psychopy, received this error: " cannot open shared object file: No such file or directory"
# Solved it this way ...
# See
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y packagekit-gtk3-module libnotify4

RUN apt-get install -y libsdl2-dev

RUN pip install psychtoolbox

This build completes without errors. I then start the container in this way:

xhost +
docker run -it --rm -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix psychopy:latest

Inside the container, it looks like psychopy was succesfully installed:

psychopy --version

… returns:

PsychoPy3, version 2021.2.3 (c)Jonathan Peirce 2018, GNU GPL license

But I cannot successfully launch psychopy. Just typing …


… returns:

pygame 2.1.2 (SDL 2.0.16, Python 3.8.10)
Hello from the pygame community.
libGL error: MESA-LOADER: failed to retrieve device information
libGL error: MESA-LOADER: failed to open amdgpu: /usr/lib/dri/ cannot open shared object file: No such file or directory (search paths /usr/lib/x86_64-linux-gnu/dri:\$${ORIGIN}/dri:/usr/lib/dri, suffix _dri)
libGL error: failed to load driver: amdgpu
libGL error: failed to open /dev/dri/card0: No such file or directory
libGL error: failed to load driver: radeonsi
Connection failure: Connection refused
pa_context_connect() failed: Connection refused
Connection failure: Connection refused
pa_context_connect() failed: Connection refused
PTB-INFO: Using modified PortAudio V19.7.0-devel, revision unknown
Error in function GetDevices: 	Usage error
PTB-ERROR: PortAudio can't detect any supported sound device on this system.
PsychPortAudio:GetDevices: Usage:

devices = PsychPortAudio('GetDevices' [, devicetype] [, deviceIndex]);
Traceback (most recent call last):
  File "/usr/local/bin/psychopy", line 8, in <module>
  File "/usr/local/lib/python3.8/dist-packages/psychopy/app/", line 100, in main
  File "/usr/local/lib/python3.8/dist-packages/psychopy/app/", line 22, in start_app
    from import PsychoPyApp
  File "/usr/local/lib/python3.8/dist-packages/psychopy/app/", line 26, in <module>
    from . import themes
  File "/usr/local/lib/python3.8/dist-packages/psychopy/app/themes/", line 1, in <module>
    from ._themes import ThemeMixin, IconCache
  File "/usr/local/lib/python3.8/dist-packages/psychopy/app/themes/", line 34, in <module>
    allCompons = components.getAllComponents()  # ensures that the icons get checked
  File "/usr/local/lib/python3.8/dist-packages/psychopy/experiment/components/", line 63, in getAllComponents
    components = getComponents(fetchIcons=fetchIcons)  # get the built-ins
  File "/usr/local/lib/python3.8/dist-packages/psychopy/experiment/components/", line 158, in getComponents
    module = import_module(explicit_rel_path, package=pkg)
  File "/usr/lib/python3.8/importlib/", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/usr/local/lib/python3.8/dist-packages/psychopy/experiment/components/microphone/", line 29, in <module>
    devices = {d.deviceName: d for d in Microphone.getDevices()}
  File "/usr/local/lib/python3.8/dist-packages/psychopy/sound/", line 549, in getDevices
    allDevs = audio.get_devices()
  File "/usr/local/lib/python3.8/dist-packages/psychtoolbox/", line 70, in get_devices
    return PsychPortAudio('GetDevices', device_type, device_index);
Exception: PTB-ERROR: PortAudio can't detect any supported sound device on this system.
0.9361 	WARNING 	Monitor specification not found. Creating a temporary one...
2.7151 	WARNING 	Speech-to-text recognition module not available (use command `pip install SpeechRecognition` to get it. Transcription will be unavailable.
2.7508 	WARNING 	We strongly recommend you activate the PTB sound engine in PsychoPy prefs as the preferred audio engine. Its timing is vastly superior. Your prefs are currently set to use ['sounddevice', 'PTB', 'pyo', 'pygame'] (in that order).
Connection failure: Connection refused
pa_context_connect() failed: Connection refused
Connection failure: Connection refused
pa_context_connect() failed: Connection refused

I don’t know how far from my goal I really am. Does this error look familiar to you? I would give this another try.

I’m sure that the tech savvy PsychoPy developers are 100 % more firm in Docker than me. So, in the long run, I guess you will want to create your own image. But perhaps this could already be a start?


The error message suggests that docker doesn’t have access to your audio card (and possibly to your graphics card either). Having access to your audio and graphics drivers is going to be absolutely key to getting PsychoPy into a vaguely useful state. I’m afraid I know a lot less than Google about that topic. :slight_smile:

Just throwing it in, in case someone is interested in testing it - what about Singularity? It’s known to be better than Docker at providing access to local devices.

I don’t know anything about singularity but, from a quick look, it seems promising. This is only going to help linux users, right? But it would provide a way that, say, ubuntu users could download a ready-to-go environment with PsychoPy and dependencies? That would be cool. A bit like being the PsychoPyStandalone equivalent for linux :smiley:

Interesting, I was trying to run psychopy in docker today .
After a lot of troubleshooting I managed to make it work including audio, though I am not using the GUI, only scripts that we currently use uncontainerized. I guess it is simpler if host/container are both ubuntu.
I extracted some clues from :


The docker run commands end up looking like

docker run \
  --device /dev/dri  \  # necessary to do opengl call apparently
  --device /dev/snd \ # sound device obviously
  -v /run/user/1000/pulse:/run/user/1000/pulse \# pulse 
  -v /tmp/.X11-unix:/tmp/.X11-unix \ # X11
  -e HOST_UID=$(id -u) -e HOST_GID=$(id -g) 
  psychopy bash

Psychopy GUI won’t launch but do not provide any error/traceback, but if I start a python I can open windows an play sounds.

Here are the Dockerfile and related files to build the docker (1.5 KB)

I’ve managed to create a Dockerfile with Ubuntu 20.04 that will launch PsychoPy GUI. GUI and audio are working. Instructions can be found here. However, there are issues with iohub and Xlib.

I’ve opened another thread to discuss PP in Singularity containers. Please check.