如何为 google colab 创建视频设备?

Shr*_*ran 3 pygame google-colaboratory

我试图在 google collab 上使用 pygame 创建一个简单的游戏,但是在执行代码 pygame.display.set_mode() 时,我收到错误“没有可用的视频设备”。那么我该如何解决呢?

Ami*_*i F 13

您可以通过告诉 SDL 使用虚拟驱动程序来抑制 pygame 使用真实显示设备的尝试,例如:

\n\n
!pip install pygame \n\nimport os\nos.environ[\'SDL_VIDEODRIVER\']=\'dummy\'\nimport pygame\npygame.display.set_mode((640,480))\n
Run Code Online (Sandbox Code Playgroud)\n\n

对我来说它发出:

\n\n
Collecting pygame\n  Downloading https://files.pythonhosted.org/packages/b3/5e/fb7c85304ad1fd52008fd25fce97a7f59e6147ae97378afc86cf0f5d9146/pygame-1.9.4-cp36-cp36m-manylinux1_x86_64.whl (12.1MB)\n    100% |\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88| 12.1MB 1.9MB/s \nInstalling collected packages: pygame\nSuccessfully installed pygame-1.9.4\npygame 1.9.4\nHello from the pygame community. https://www.pygame.org/contribute.html\n<Surface(640x480x8 SW)>\n
Run Code Online (Sandbox Code Playgroud)\n\n

(注意,这不会将 GPU 用于虚拟“显示”;我假设您只想将 colab GPU 用于 AI/ML)

\n