Tl;dr
I need to use pygame
but it can't initialize the screen as a normal user because of the permissions for the framebuffer driver. root can do pygame.display.init()
but not the user. User is in the group 'video' and can write on /dev/fb0
. What permission is missing to the user so pygame.display.init()
would work.
Error encountered : pygame.error: Unable to open a console terminal
Description
So, I am trying to use pygame in order to display things on a framebuffer /dev/fb0
.
To use some functions I need (e.g pygame.Surface.convert
) the display must be initialized. However, when calling pygame.display.init()
I have an error, but only when not doing so as root.
According to @Nodraak (ref) it is related to the permissions of the framebuffer driver.
Late answer but I wish I would have tried that earlier :
You may need to be root to use a frame buffer driver.
(It helped in my case: RaspberryPi 2 without X running but with a screen connected. I can now open a display through SSH or directly on the RPi)
A tree -fupg / | grep fb | grep rwx
doesn't seem to show any binary which would be executable by root but not by others. I am quite sure that adding my user to a group, or tweaking the file permissions somewhere would be enough to fix the issue.
Note: For Security reasons, running the software as root is not an option.
Context
- System : RaspberryPi
- X Server: None
- Screen: 1 (HDMI)
- Connection: remote (SSH)
Origin of the error
I am trying to convert a surface with pygame.Surface.convert(...)
function. But receive the following error :
pygame.error: cannot convert without pygame.display initialized
Nevertheless, initializing pygame.display with pygame.display.init()
is giving the following error:
pygame.error: Unable to open a console terminal
I have the rights to write to the screen as I am part of the video
group, and cat /dev/urandom > /dev/fb0
is effectively displaying snow on the screen.
Also I tried setting up the SDL_... environment variable to fbcon
or dummy
but it doesn't help. I also tried keeping the root env with user su -m user
and same result.
Reproduce the error
On a raspberrypi without XServer, connect an HDMI screen, install pygame.
import pygame
pygame.display.init()
Error message:
pygame.error: Unable to open a console terminal
Software Versions
python 3.7.3
pygame 1.9.4.post1
OS Raspbian Buster
libsdl 2