How Can We Use Pygame On Google Colab?
Solution 1:
PyGame
can use only local video card and local monitor.
When you run code on server then it try to use video card installed in server and monitor connected to this server which you can't see.
But you can't even run it because usually servers don't have video card and monitor because nobody could see this monitor (except server's admin).
EDIT: if server has video card then you have to run pygame.display.init()
before list_modes()
pygame.display.init()
print( pygame.display.list_modes() )
or pygame.init()
which should run pygame.display.init()
(and other init()
)
pygame.init()
print( pygame.display.list_modes() )
Solution 2:
There is a way to run pygame in Colab with some limitations.
- Fool the system to think there is a video device
- Capture the pygame screen and copy it to another interface compatible with Colab like OpenCV or matplotlib
- Use output library to clear the cell.
Not the most elegant way, but it gets it done.
Take a look at this notebook I created: (https://colab.research.google.com/drive/1xtiBrGeRHmXY3KSOixkZBf_rJIgBImJu?usp=sharing)
Please notice there are limitations:
- Can't read inputs from keyboard or mouse
- Can't play audios
In my case I was interested to use pygame for animation purposes so I wasn't too fuzzed about it.
Post a Comment for "How Can We Use Pygame On Google Colab?"