pygame:不打开窗口/'pygame.error:没有可用的视频设备' [英] pygame: doesn't open window / 'pygame.error: No available video device'
问题描述
我目前正在尝试让 pygame 在我的 Ubuntu 20.04 机器上运行.收到错误无可用视频设备"后,我添加了以下代码行:
I am currently trying to make pygame run on my Ubuntu 20.04 machine. After getting the error 'No available video device' I added the following lines of code:
import os
os.environ['SDL_VIDEODRIVER'] = 'dummy'
现在错误信息消失了,但窗口仍然没有弹出......我使用的是 python 3.8.3 和 pygame 2.0.0.dev10.
Now the error message is gone, but the window still does not pop up... I am using python 3.8.3 and pygame 2.0.0.dev10.
有人知道我错过了什么吗?
Does somebody know what I am missing?
推荐答案
因为将 SDL_VIDEODRIVER
设置为 dummy"
它实际上不会渲染任何内容.如维基底部所述:
Because setting SDL_VIDEODRIVER
to "dummy"
it won't actually render anything. As stated at the bottom of the wiki:
如果您需要事件队列但不想要真正的窗口,请在调用 SDL_SetVideoMode 之前尝试 putenv("SDL_VIDEODRIVER=dummy").我发现这在使用 SDL 工具但不需要真正的视频输出设备的应用程序中很有用.
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
的值设置为可以找到的 Linux 视频驱动程序之一此处.
Since you are on Linux, you will need to set the value of SDL_VIDEODRIVER
to one of the Linux video drivers which can be found here.
如果还是不行,你可能需要重新安装显卡驱动或者您的 SDL 软件包之一出现问题,可能需要重新安装.
If it still doesn't work, you may need to re-install your video drivers or something is wrong with one of your SDL packages and they may need to be re-installed.
这篇关于pygame:不打开窗口/'pygame.error:没有可用的视频设备'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!