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.

Cheers,
Michael

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.

Cheers,
Michael

Hi,

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 https://dev.to/0xbf/set-timezone-in-your-docker-image-d22
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 https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-20.04/wxPython-4.1.0-cp38-cp38-linux_x86_64.whl
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: "libgtk-3.so.0: cannot open shared object file: No such file or directory"
# Solved it this way ...
# See https://stackoverflow.com/questions/50768064/firefox-cannot-open-libgtk-3-so-0-how-to-circumvent
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y packagekit-gtk3-module libnotify4

# https://stackoverflow.com/questions/29711336/libsdl2-2-0-so-0-cannot-open-shared-object-file
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 …

psychopy

… returns:

pygame 2.1.2 (SDL 2.0.16, Python 3.8.10)
Hello from the pygame community. https://www.pygame.org/contribute.html
libGL error: MESA-LOADER: failed to retrieve device information
libGL error: MESA-LOADER: failed to open amdgpu: /usr/lib/dri/amdgpu_dri.so: 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>
    sys.exit(main())
  File "/usr/local/lib/python3.8/dist-packages/psychopy/app/psychopyApp.py", line 100, in main
    start_app()
  File "/usr/local/lib/python3.8/dist-packages/psychopy/app/psychopyApp.py", line 22, in start_app
    from psychopy.app._psychopyApp import PsychoPyApp
  File "/usr/local/lib/python3.8/dist-packages/psychopy/app/_psychopyApp.py", line 26, in <module>
    from . import themes
  File "/usr/local/lib/python3.8/dist-packages/psychopy/app/themes/__init__.py", line 1, in <module>
    from ._themes import ThemeMixin, IconCache
  File "/usr/local/lib/python3.8/dist-packages/psychopy/app/themes/_themes.py", line 34, in <module>
    allCompons = components.getAllComponents()  # ensures that the icons get checked
  File "/usr/local/lib/python3.8/dist-packages/psychopy/experiment/components/__init__.py", line 63, in getAllComponents
    components = getComponents(fetchIcons=fetchIcons)  # get the built-ins
  File "/usr/local/lib/python3.8/dist-packages/psychopy/experiment/components/__init__.py", line 158, in getComponents
    module = import_module(explicit_rel_path, package=pkg)
  File "/usr/lib/python3.8/importlib/__init__.py", 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/__init__.py", line 29, in <module>
    devices = {d.deviceName: d for d in Microphone.getDevices()}
  File "/usr/local/lib/python3.8/dist-packages/psychopy/sound/microphone.py", line 549, in getDevices
    allDevs = audio.get_devices()
  File "/usr/local/lib/python3.8/dist-packages/psychtoolbox/audio.py", 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?

Cheers,
Michael

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 :

  • https://github.com/TheBiggerGuy/docker-pulseaudio-example
  • https://github.com/aoirint/psychopy-docker

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) 
  -e DISPLAY 
  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

psychopy-docker.zip (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.