Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Vinalti opened this issue Jan 24, 2022 · 4 comments
Open

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

Vinalti opened this issue Jan 24, 2022 · 4 comments
Labels

Comments

@Vinalti
Copy link

Vinalti commented Jan 24, 2022

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.
@Vinalti Vinalti added the bug label Jan 24, 2022
@ankith26
Copy link
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

@Vinalti
Copy link
Author

Vinalti commented Jan 31, 2022

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 ).

@robertpfeiffer
Copy link
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

@robertpfeiffer
Copy link
Contributor

It feels like there is some vital context missing here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants