Code runs, but no game video displays


#1

I appear to have everything working, but no video displays. I’m running the cart-pole game, and expecting to see a video somewhere. I run the code here:

import gym
env = gym.make('CartPole-v0')
for i_episode in range(20):
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

And it runs with no errors, I believe. Here is the last unit of output of the 100 that run, for example:

[-0.0049835   0.01538605  0.02175562  0.03357809]
[-0.00467578  0.21018937  0.02242718 -0.25216209]
[-0.00047199  0.01475447  0.01738394  0.04750957]
...
[ 0.10793621  0.99143914 -0.12587693 -1.44867121]
[ 0.127765    0.7980694  -0.15485035 -1.19782169]
[ 0.14372638  0.99481845 -0.17880678 -1.53475829]
Episode finished after 16 timesteps

But I don’t see the actual visual of the game running, which the instructions on the getting started page say should display.

I’m running over Putty, and also tried it in an X terminal. I’m running this on a RHEL 6.8 server but need it all to render on my Windows client.

I’ve tried this, per several topics here:

xvfb-run -a -s "-screen 0 1400x900x24 +extension RANDR" -- python cart-pole.py

It doesn’t help. Where cart-pole.py contains the code shown above. Besides, isn’t “headless” precisely what I don’t want? I do want to see the video. I thought xvfb-run would be what I do when I want to just run it fast without seeing it.

I’ve also tried this:

xvfb-run -a -s "-screen 0 1400x900x24 +extension RANDR" -- bash

And then ran cart-pole.py in the new bash session. Same results.

I get no error messages, either on the screen, or in the xvfb-run log file.

If I run glxgears and glxinfo, they run fine, both as part of the xfvb-run command, and if I do a new bash shell via xvfb-run and just run it:

4306 frames in 5.0 seconds = 861.196 FPS
4555 frames in 5.0 seconds = 910.805 FPS
4637 frames in 5.0 seconds = 927.253 FPS

My Windows machine is running Exceed 14. I can pop other X apps, such as xclock.

Why can’t I see the game render?

All help appreciated!


#2

I think you need the wrapper,

env = wrappers.Monitor(env, “temp directory”)