Is there a Docker image for PsychoPy?

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