Solving your issue required getting the right combination of system dependencies and python dependencies. Paste this code into a cell in Colab and run it to install all of the dependencies (taking note of the specific version numbers used).
%%bash
# install required system dependencies
apt-get install -y xvfb x11-utils
# install required python dependencies (might need to install additional gym extras depending)
pip install gym[box2d]==0.17.* pyvirtualdisplay==0.2.* PyOpenGL==3.1.* PyOpenGL-accelerate==3.1.*
The final step is to run the following block of code to properly initialize the virtual display. The code in the below creates a virtual display in the background that your Gym Envs can connect to for rendering. You can adjust the size of the virtual buffer as you like but you must set visible=False
when working with Xvfb.
This code only needs to be run once per session to start the display.
import pyvirtualdisplay
_display = pyvirtualdisplay.Display(visible=False, # use False with Xvfb
size=(1400, 900))
_ = _display.start()
For additional details check out the following blog post.