Tl;dr
我需要使用pygame
但由于权限问题,它无法以普通用户身份初始化屏幕帧缓冲驱动程序。根可以做pygame.display.init()
但不是用户。用户位于“视频”组中,可以在其上书写/dev/fb0
。用户缺少什么权限pygame.display.init()
会工作。
遇到错误:pygame.error: Unable to open a console terminal
描述
所以,我正在尝试使用pygame为了在帧缓冲区上显示内容/dev/fb0
。
要使用我需要的一些功能(例如pygame.Surface.convert
)显示器必须初始化。然而,当打电话时pygame.display.init()
我有一个错误,但只有在不以 root 身份执行此操作时才会出现错误。
根据@Nodraak(ref) https://stackoverflow.com/a/33828394/17965313这与权限有关帧缓冲驱动程序.
迟到的答案,但我希望我早点尝试过:
您可能需要成为 root 才能使用帧缓冲区驱动程序。
(这对我的情况有帮助:RaspberryPi 2 没有 X 运行,但有
屏幕已连接。我现在可以通过 SSH 或直接在
RPi)
A tree -fupg / | grep fb | grep rwx
似乎没有显示任何可以由 root 执行但不能由其他人执行的二进制文件。我非常确定将我的用户添加到组中,或在某处调整文件权限就足以解决问题。
注意:出于安全原因,不能以 root 身份运行软件。
Context
- 系统:树莓派
- X 服务器:无
- 屏幕:1(HDMI)
- 连接:远程(SSH)
错误的根源
我正在尝试使用以下方法转换表面pygame.Surface.convert(...)
功能。但收到以下错误:
pygame.error: cannot convert without pygame.display initialized
尽管如此,初始化 pygame.display 与pygame.display.init()
给出以下错误:
pygame.error: Unable to open a console terminal
我有权在屏幕上书写,因为我是video
组,以及cat /dev/urandom > /dev/fb0
有效地在屏幕上显示雪。
我还尝试将 SDL_... 环境变量设置为fbcon
or dummy
但这没有帮助。我还尝试将根环境与用户一起保留su -m user
和相同的结果。
重现错误
在没有 XServer 的树莓派上,连接 HDMI 屏幕,安装 pygame。
import pygame
pygame.display.init()
错误信息:
pygame.error: Unable to open a console terminal
软件版本
python 3.7.3
pygame 1.9.4.post1
OS Raspbian Buster
libsdl 2
Related
- Pygame.display.init 文档 https://www.pygame.org/docs/ref/display.html#pygame.display.init
- 所以问题:Pygame 在无头 Raspberry 上显示 init(...) https://stackoverflow.com/q/57418067/17965313