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