1

我正在尝试在 google collab 上使用 pygame 创建一个简单的游戏,但是在执行代码 pygame.display.set_mode() 时出现错误 No available video device。那么我该如何解决呢?

4

1 回答 1

5

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

!pip install pygame 

import os
os.environ['SDL_VIDEODRIVER']='dummy'
import pygame
pygame.display.set_mode((640,480))

对我来说,它发出:

Collecting pygame
  Downloading https://files.pythonhosted.org/packages/b3/5e/fb7c85304ad1fd52008fd25fce97a7f59e6147ae97378afc86cf0f5d9146/pygame-1.9.4-cp36-cp36m-manylinux1_x86_64.whl (12.1MB)
    100% |████████████████████████████████| 12.1MB 1.9MB/s 
Installing collected packages: pygame
Successfully installed pygame-1.9.4
pygame 1.9.4
Hello from the pygame community. https://www.pygame.org/contribute.html
<Surface(640x480x8 SW)>

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

于 2019-01-04T22:27:08.987 回答