【问题标题】:How to create a video device for google colab?如何为 google colab 创建视频设备?
【发布时间】:2020-09-17 20:44:55
【问题描述】:

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

【问题讨论】:

  • 您可以通过在视频设备可用的环境中运行代码来解决它,通常这意味着您的台式电脑。
  • 是的,我知道,但我的桌面没有 GPU,我正在尝试构建一个 AI 来玩游戏

标签: pygame google-colaboratory


【解决方案1】:

您可以通过告诉 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-12-14
  • 2022-01-21
  • 2020-03-28
  • 2020-02-15
  • 2020-08-17
  • 2020-07-19
  • 1970-01-01
  • 2020-08-15
  • 1970-01-01
相关资源
最近更新 更多