| Reference | Downloads | Github

Ubuntu, Psychtoolbox Keyboard Error

If this template helps then use it. If not then just delete and start from scratch.

OS (e.g. Win10): Ubuntu 18.04
PsychoPy version (e.g. 1.84.x): v3.2.4
Standard Standalone? (y/n) If not then what?: y
What are you trying to achieve?: I want to solve an issue

What did you try to make it work?: I tried to follow the task of the first chapter of the book: Building experiments in PsychoPy. I wanted to simply run the Stroop task.

What specifically went wrong when you tried that?:
Include pasted full error message if possible. “That didn’t work” is not enough information.

This is how anyone can replicate my situation.

  1. In the builder view, create a text stimulus.

  2. Run it.

  3. Below are the messages that I see:
    PsychHID-WARNING: Failed to setup international keyboard handling due to failed input context creation.
    PsychHID-WARNING: Only US keyboard layouts will be mapped properly due to this failure for GetChar() et al.
    PTB-CRITICAL: In call to PsychSetThreadPriority(): Failed to set new basePriority 2, tweakPriority 1, effective 1 [REALTIME] for thread (nil) provided!
    PsychHID: KbQueueStart: Failed to switch to realtime priority [Operation not permitted].
    Fatal Python error: (pygame parachute) Segmentation Fault

  4. When I go to the Coder view and read over the code, lines 78-79 are:
    #create a default keyboard (e.g. to check for escape)
    defaultKeyboard = keyboard.Keyboard()

Then lines 140-142 go:
#check for quit (typically the Esc key)
if endExpNow or defaultKeyboard.getKeys(keyList=[“escape”]):

I figured out that if I just comment out line 79 and then replace “defaultKeyboard.getKeys” attribute with “event.getKeys” it works without any issue.

I don’t understand why should it be done this way. I am frustrated to know that the builder view does not even let me run a simple task.

Let me know if I have missed anything. This is my fifth attempt to work with PsychoPy, and this is certainly not a pleasant experience. I feel like it’s an issue related to psychtoolbox module.

In addition, when I run python 3.6.9(which is the version coupled with PsychoPy) and run the following lines:

from psychopy.hardware import keyboard
defaultkeyboard = keyboard.Keyboard()

Python crashes. What am I MISSING?

*note: Ok. I am using a non US keyboard, so that may be another reason.
I have read, so I am aware of the change.
Nonetheless, would there be an option to set event.getKeys() as the default call???

It is not Builder that is having the issue here, but, as the error notes and you yourself conclude, it is an issue with the Psychtoolbox library and your particular system configuration. On Windows and Mac, you can get everything bundled together in the standalone app, but on Linux, you are responsible for handling the dependencies, which may pose issues that are idiosyncratic to your particular setup.

Having said that, if the issue is reproducible and likely to affect others, you should submit a detailed issue report at:

Just uninstall the psychtoolbox package. In its absence, the Keyboard class is smart enough to fall back on the event module automatically:

PsychoPy is an open-source project, created by people volunteering their time because they are passionate about providing software for themselves and others to do good science. You might want to consider that when phrasing assistance requests on this forum, which are, again, responded to largely freely and voluntarily as a service to others.


Thank you for your answer. I appreciate it.

I do understand that it is my responsibility as a Linux user to look further and try different solutions.
However, due to my limitation as a non computer scientist, I can only understand so much about what’s happening when things don’t work out. I also do understand that python libraries are supported by those who are voluntarily helping others. If my comment sounded like an unsatisfied customer who was paying for a license, I will be mindful of my language in the future.