I am running a python 2.7 script on a p2.xlarge AWS server through Jupyter (Ubuntu 14.04). I would like to be able to render my simulations.
Minimal working example<
I encountered the same problem and stumbled upon the answers here. Mixing them helped me to solve the problem.
Here's a step by step solution:
Install the following:
apt-get install -y python-opengl xvfb
Start your jupyter notebook via the following command:
xvfb-run -s "-screen 0 1400x900x24" jupyter notebook
Inside the notebook:
import gym
import matplotlib.pyplot as plt
%matplotlib inline
env = gym.make('MountainCar-v0') # insert your favorite environment
env.reset()
plt.imshow(env.render(mode='rgb_array')
Now you can put the same thing in a loop to render it multiple times.
from IPython import display
for _ in range(100):
plt.imshow(env.render(mode='rgb_array'))
display.display(plt.gcf())
display.clear_output(wait=True)
action = env.action_space.sample()
env.step(action)
Hope this works for anyone else still facing an issue. Thanks to Andrews and Nathan for their answers.