I am trying to create a simple game using pygame on google collab, but on executing the code pygame.display.set_mode() I get the error No available video device. So how do I resolve it?
Asked
Active
Viewed 1.5k times
2
-
You resolve it by running the code in an environment where a video device is available, usually that means your desktop PC. – sloth Jan 04 '19 at 12:37
-
Yeah, i know that, but my desktop does not have a GPU and i am trying to build an ai to play the game – Shreyas Ramachandran Jan 04 '19 at 14:13
1 Answers
13
You can suppress pygame's attempt to use a real display device by telling SDL to use a dummy driver like:
!pip install pygame
import os
os.environ['SDL_VIDEODRIVER']='dummy'
import pygame
pygame.display.set_mode((640,480))
which for me emits:
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., this won't use the GPU for the dummy "display"; I'm assuming you only want to use the colab GPU for AI/ML)

Ami F
- 2,202
- 11
- 19
-
1Hello. Is there any way that the surface to be shown/rendered on my local computer?! – Pouyan Aug 02 '20 at 13:50