Way to train without opening a window?


I’m trying to train an agent on a Jupyter Notebook but without allowing a window of the training process to open. Is there a switch I can pass and prevent it from happening? I’m not even calling the env.render() method, though I’m monitoring so that I can later show the video recording.


I’m working on the CartPole example:

import io
import gym
import base64
import tempfile

from IPython.display import HTML
from gym.monitoring import VideoRecorder

env = gym.make('CartPole-v0')
rec = VideoRecorder(env)

for i_episode in range(20):
    observation = env.reset()
    for t in range(100):
        action = env.action_space.sample()
        observation, reward, done, info = env.step(action)
        if done:
            print("Episode finished after {} timesteps".format(t+1))

And later showing the video with:

video = io.open(rec.path, 'r+b').read()
encoded = base64.b64encode(video)

html_tag = """
<video width="960" height="540" controls>
    <source src="data:video/mp4;base64,{0}" type="video/mp4" />


I was trying this too; rec.capture_frame() errors like here.