python - pygame:不打开窗口/'pygame.error: No available video device'

标签 python linux ubuntu pygame

我目前正在尝试让 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/

相关文章:

python - 如何pandas解析之前保存的json

linux - 配置 LDAP 时出现 Berkeley DB 不匹配错误

linux - sed:打印带有时间和 ls -altr info 的目录树

python-3.x - 如何将 .py 文件从 Ubuntu 制作为 .exe 以在 Windows 上运行?

postgresql - Postgres 9.4 0 undefined symbol - PQhostaddr

python - Spyder新手看不到生成的图表

python - NumPy 数组数组到 PyOpenCL vecs 数组

python - 在python中使用类型提示注释路径的正确方法是什么?

c - 重命名 gcov 文件以进行各种编译

java - JDK 和 IDEA 在 Ubuntu 上忽略 $HOME