Pygame headless setup

拜拜、爱过 提交于 2019-12-01 17:02:22

问题


I am using pygame's joystick api to use a joystick with my project on a headless system, but pygame requires a "screen" so I have setup a dummy video system to over come this. It worked fine but now all of a sudden it gives me this error:

Traceback (most recent call last):
  File "compact.py", line 10, in <module>
    screen = display.set_mode((1, 1))
pygame.error: Unable to open a console terminal

Here is what I have as the headless setup that is supposed to over come this issue.

from pygame import *
import os
import RPi.GPIO as GPIO
os.environ["SDL_VIDEODRIVER"] = "dummy"
screen = display.set_mode((1, 1))

回答1:


Pygame is trying to open a console which means you're running this script through ssh or cron or somewhere else that doesn't have access to the console. I would try skipping set_mode (since the dummy driver likely doesn't have modes to set) and just try to initialize the display. You can try running it as root which might give it access. You can also try telling it to use fbcon.

os.putenv('SDL_VIDEODRIVER', 'fbcon')
pygame.display.init()


来源:https://stackoverflow.com/questions/32900155/pygame-headless-setup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!