Skip to content

pygame.display.init fails if not started by root on Raspberry Pi #3003

Open

Description

@Vinalti

Environment:

You can get some of this info from the text that pops up in the console when you run a pygame program.

  • Operating system : RaspberryPi OS - No XServer - Light version
  • Python version: 3.7.3
  • SDL version : 2.x.x ?
  • PyGame version : 1.9.4.post1
  • Relevant hardware : Raspberry Pi 4 - Connected to a LCD HDMI Screen

Current behavior:
When user runs display.init() an error happens : pygame.error: Unable to open a console terminal

import pygame
pygame.display.init()
# pygame.error: Unable to open a console terminal

If run as root, everything is working.

Expected behavior:
If user as proper persmission display.init should work

Steps to reproduce:
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

Stack trace/error output/other error logs

pygame.error: Unable to open a console terminal

No stacktrace

QUESTION

What permissions is needed to have display.init() working as non-root user ?

More details : https://stackoverflow.com/q/70757953/17965313

Notes

  • Setting environment variable SDL_VIDEODRIVER to fbcon or dummy is not solving the issue
  • Root can do a display.init() without problem
  • There are no XServer running so DISPLAY is not set and doesn't exist.
  • I need to do a dispay.init() however I don't need a display.

Activity

  1. ankith26 commented on Jan 30, 2022

    @ankith26
    Contributor

    Hi! First of all, pygame 1.9.4 is a rather dated version of pygame, perhaps you should upgrade to pygame 2.1.2 (fair warning, pygame2 has issues on pi hardware ATM, so this will likely be slower than pygame 1.9.4)
    I'm not really sure, but I believe the videodriver should be set to fbcon in your case. If you used sudo while setting the environment variable, it is invisible to processes run without sudo. So remember to set the environment variable without sudo

  2. Vinalti commented on Jan 31, 2022

    @Vinalti
    Author

    Hello @ankith26, thank you for your answer, I tried setting up the SDL_VIDEODRIVER environment variable (directly in the python code with os.environ[...] = ... ) but it doesn't help. Also I don't need to do this to make it work as root, so I think it is a permission issue. Nevertheless I couldn't find which file would it be.
    Version 1.9.4 is working fine (is the default when using apt install python3-pygame) and I have the same issue nevertheless with the version 2.1.2 (installed with pip install pygame ).

  3. robertpfeiffer commented on Mar 31, 2022

    @robertpfeiffer
    Contributor

    Which version of Raspberry Pi OS are you on? With the latest version of PyGame and Pi OS, I would not recommend fbcon (but that would be correct for PyGame 1.9.4) but KMS/DRM. https://wiki.libsdl.org/FAQUsingSDL

  4. robertpfeiffer commented on Mar 31, 2022

    @robertpfeiffer
    Contributor

    It feels like there is some vital context missing here

  5. SpudGunMan commented on Apr 24, 2025

    @SpudGunMan

    I cant get pygame to work on a new Pi with attached LCD pi3 or Pi4 it just hangs on init
    running python in sudo things work fine.. everything was downloaded and updated for same date as this post

  6. SpudGunMan commented on Apr 24, 2025

    @SpudGunMan

    figured out a work around!
    find your display, likely fb0
    ls -l /dev/fb*
    allow all access
    sudo chmod a+rw /dev/fb0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions