title: How to run OpenAI Gym .render() over a server
body: <p>I am running a python 2.7 script on a p2.xlarge <a href="https://aws.amazon.com/" rel="noreferrer">AWS</a> server through Jupyter (Ubuntu 14.04). I would like to be able to render my simulations.</p>
  
  <p>Minimal working example</p>
  
  <pre><code>import gym
  env = gym.make('CartPole-v0')
  env.reset()
  env.render()
  </code></pre>
  
  <p><code>env.render()</code> makes (among other things) the following errors:</p>
  
  <pre><code>...
  HINT: make sure you have OpenGL install. On Ubuntu, you can run 
  'apt-get install python-opengl'. If you're running on a server, 
  you may need a virtual frame buffer; something like this should work: 
  'xvfb-run -s \"-screen 0 1400x900x24\" python &lt;your_script.py&gt;'")
  ...
  NoSuchDisplayException: Cannot connect to "None"
  </code></pre>
  
  <p>I would like to some how be able to see the simulations. It would be ideal if I could get it inline, but any display method would be nice.</p>
  
  <p><strong>Edit</strong>: This is only an issue with some environments, like classic control.</p>
  
  <hr>
  
  <p><strong>Update I</strong></p>
  
  <p>Inspired by <a href="https://stackoverflow.com/questions/16726227/xvfb-failed-start-error">this</a> I tried the following, instead of the <code>xvfb-run -s \"-screen 0 1400x900x24\" python &lt;your_script.py&gt;</code> (which I couldn't get to work).</p>
  
  <pre><code>xvfb-run -a jupyter notebook
  </code></pre>
  
  <p>Running the original script I now get instead</p>
  
  <pre><code>GLXInfoException: pyglet requires an X server with GLX
  </code></pre>
  
  <hr>
  
  <p><strong>Update II</strong></p>
  
  <p>Issue <a href="https://github.com/openai/gym/issues/152" rel="noreferrer">#154</a> seems relevant. I tried disabling the pop-up, and directly creating the RGB colors</p>
  
  <pre><code>import gym
  env = gym.make('CartPole-v0')
  env.reset()
  
  img = env.render(mode='rgb_array', close=True)  
  print(type(img)) # &lt;--- &lt;type 'NoneType'&gt;
  
  img = env.render(mode='rgb_array', close=False) # &lt;--- ERROR
  print(type(img)) 
  </code></pre>
  
  <p>I get <code>ImportError: cannot import name gl_info</code>.</p>
  
  <hr>
  
  <p><strong>Update III</strong></p>
  
  <p>With inspiration from @<a href="https://stackoverflow.com/users/929999/torxed">Torxed</a> I tried creating a video file, and then rendering it (a fully satisfying solution).</p>
  
  <p>Using the code from '<a href="https://gym.openai.com/docs" rel="noreferrer">Recording and uploading results</a>' </p>
  
  <pre><code>import gym
  
  env = gym.make('CartPole-v0')
  env.monitor.start('/tmp/cartpole-experiment-1', force=True)
  observation = env.reset()
  for t in range(100):
  #    env.render()
      print(observation)
      action = env.action_space.sample()
      observation, reward, done, info = env.step(action)
      if done:
          print("Episode finished after {} timesteps".format(t+1))
          break
  
  env.monitor.close()
  </code></pre>
  
  <p>I tried following your suggestions, but got <code>ImportError: cannot import name gl_info</code> from when running <code>env.monitor.start(...</code>. </p>
  
  <p>From my understanding the problem is that OpenAI uses <code>pyglet</code>, and <code>pyglet</code> 'needs' a screen in order to compute the RGB colors of the image that is to be rendered. <em>It is therefore necessary to trick python to think that there is a monitor connected</em></p>
  
  <hr>
  
  <p><strong>Update IV</strong></p>
  
  <p>FYI there are solutions online using bumblebee that seem to work. This should work if you have control over the server, but since AWS run in a VM I don't think you can use this.</p>
  
  <hr>
  
  <p><strong>Update V</strong></p>
  
  <p>Just if you have this problem, and don't know what to do (like me) the state of most environments are simple enough that you can create your own rendering mechanism. Not very satisfying, but.. you know.</p>