Pygame 无头设置 [英] Pygame headless setup

查看:28
本文介绍了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天全站免登陆