pygame无头设置 [英] Pygame headless setup

查看:121
本文介绍了pygame无头设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用pygame的游戏杆api在无头系统上的项目中使用游戏杆,但是pygame需要一个屏幕",因此我设置了虚拟视频系统来克服这个问题.一切正常,但突然之间出现了这个错误:

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试图打开控制台,这意味着您正在通过ssh或cron或其他无法访问该控制台的地方运行此脚本.我会尝试跳过set_mode(因为虚拟驱动程序可能没有要设置的模式),而只是尝试初始化显示.您可以尝试以root用户身份运行它,这可能会使它具有访问权限.您也可以尝试告诉它使用fbcon.

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

这篇关于pygame无头设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆