pygame:未打开窗口/“pygame.error:没有可用的视频设备”

2024-05-17 13:08:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我目前正试图让pygame在我的Ubuntu20.04机器上运行。在收到错误“没有可用的视频设备”后,我添加了以下代码行:

import os
os.environ['SDL_VIDEODRIVER'] = 'dummy'

现在错误信息消失了,但窗口仍然没有弹出。。。 我正在使用python 3.8.3和pygame 2.0.0.dev10

有人知道我错过了什么吗


Tags: 代码import机器视频dev10os错误environ
1条回答
网友
1楼 · 发布于 2024-05-17 13:08:47

因为将SDL_VIDEODRIVER设置为"dummy"实际上不会呈现任何内容As stated at the bottom of the wiki

If you need an event queue but don't want a real window, try putenv("SDL_VIDEODRIVER=dummy") before you call SDL_SetVideoMode. I find this useful in apps that use SDL facilities, but don't need a real video output device.

由于您使用的是Linux,因此需要将SDL_VIDEODRIVER的值设置为可以找到here的一个Linux视频驱动程序

如果它仍然无法工作,您可能需要重新安装视频驱动程序或something is wrong with one of your SDL packages,并且可能需要重新安装它们

相关问题 更多 >