我目前正在尝试让 pygame 在我的 Ubuntu 20.04 机器上运行。收到错误“没有可用的视频设备”后,我添加了以下代码行:
import os
os.environ['SDL_VIDEODRIVER'] = 'dummy'
现在错误信息消失了,但窗口仍然没有弹出......我正在使用 python 3.8.3 和 pygame 2.0.0.dev10。
有人知道我错过了什么吗?
最佳答案
因为设置 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
的值。到 Linux 视频驱动程序之一,可以找到 here .如果仍然无法正常工作,您可能需要重新安装视频驱动程序或something is wrong with one of your SDL packages他们可能需要重新安装。
关于python - pygame:不打开窗口/'pygame.error: No available video device',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64379965/