Giter Club home page Giter Club logo

Comments (23)

joschu avatar joschu commented on May 13, 2024 31

You should be able to do env.render(close=True)

from gym.

cuongqn avatar cuongqn commented on May 13, 2024 15

@ahsteven I think close is now a top level method. Using env.close() at the end when you want to close the window works for Windows 10 on Python 3.5.0.

from gym.

skyler237 avatar skyler237 commented on May 13, 2024 8

A workaround I found is to simply wrap the training/simulation loop in a try-finally block so that even if I exit the loop early, the window will close.

For example:

try:
    # training loop
finally:
    env.close()

This worked for me.

from gym.

nemanja-rakicevic avatar nemanja-rakicevic commented on May 13, 2024 7

In the new version of gym==0.9 you should use env.close() but it doesn't close the render window...
(neither before or after kernel interrupt)
I am using Ubuntu 16.04 and python 3.5

from gym.

insublee avatar insublee commented on May 13, 2024 4

env.render(close=True)
didn't work for me. but
env.render(mode='close')
work.

from gym.

samisnotinsane avatar samisnotinsane commented on May 13, 2024 4

This issue is still ongoing. When I run CartPole-v0 demo:

import gym

env = gym.make('CartPole-v0')
env.reset()


for _ in range(1000):
    env.render()
    env.step(env.action_space.sample()) #take a random action

env.close()

The demo runs and then when I go to close it by clicking red X on the window, it freezes. I can force quit using OS and this kills the kernel. Once I restart kernel, I can run again but same behaviour repeats.

System spec:

Mac OS Big Sur   : 11.2.3
Python           : 3.8.5
Gym              : 0.18.0
jupyter core     : 4.7.0
jupyter-notebook : 6.1.4
qtconsole        : not installed
ipython          : 7.19.0
ipykernel        : 5.3.4
jupyter client   : 6.1.7
jupyter lab      : 2.2.9
nbconvert        : 6.0.7
ipywidgets       : 7.5.1
nbformat         : 5.0.8
traitlets        : 5.0.5

from gym.

jimhoggey avatar jimhoggey commented on May 13, 2024 2

env.render(close=True)

This did not work for me in gym retro parallel learning
but what did work was self.env.render(close=True)
Thanks so much for the help
This has been a long issue that I could't fix but I finally did :)))))

from gym.

iandanforth avatar iandanforth commented on May 13, 2024 1

Thanks! That works. FYI my thought process was to 1. Try reset 2. look for top level methods like env.exit, env.stop, env.close etc.

from gym.

gdb avatar gdb commented on May 13, 2024 1

Yeah, the render(close=...) method is definitely a compromise: we want to keep the env API as simple as possible, both for implementors and consumers of the interface. I didn't want to add a top-level close method, since it's hard to know exactly what that'd mean (is the environment now permanently dead)? But if things get more complex, we could add a linked renderer object a la monitor.

I'll close this for now, and see how many other people get confused :).

from gym.

capybaralet avatar capybaralet commented on May 13, 2024 1

I have this problem as well.

If I make two envs (both called env), I lose the handle for the first one, so I can't close the window with env.render.

Is there a solution in this case? (other than closing the interactive session)

from gym.

tlbtlbtlb avatar tlbtlbtlb commented on May 13, 2024 1

If you don't need the window at all, just don't call env.render().

from gym.

sprakashdash avatar sprakashdash commented on May 13, 2024 1

You can also try env.close(). That too works for me!

from gym.

DhruvaG2000 avatar DhruvaG2000 commented on May 13, 2024 1

I am using jupyter-notebook
env.render(close=True)
didn't work, it says 'close' keyword not recognized.
env.close() worked better, but even then sometimes a black window remained.
I had to exit() to close in that case. I guess gym isn't made to run in ipython-like environments?

from gym.

sprakashdash avatar sprakashdash commented on May 13, 2024 1

The version compatibility might be an issue. The best compatibility is found with python 3.6 and gym 0.15. Another hack is to use env.render() at the end of the for loop to close the window (in the same cell) and it works like charm!

from gym.

erickrf avatar erickrf commented on May 13, 2024

I can't solve the problem with env.render(close=True) under macOS Sierra. If I try it, the renderized window just goes blank. Each time I call env.render(), a new window is created, and I can see all of them under mission control. Is there some way to close them?

from gym.

ethanluoyc avatar ethanluoyc commented on May 13, 2024

I think this API is rather confusing indeed. I expect is to allow me to render the rgb view without opening a window but apparently that is not what it is doing. How can I get the desired behaviour?

from gym.

tlbtlbtlb avatar tlbtlbtlb commented on May 13, 2024

from gym.

ethanluoyc avatar ethanluoyc commented on May 13, 2024

That is unfortunate. I do not really have a hard requirement for not displaying the window, but it is just that sometimes I do not need to see the window at all during training.

from gym.

ethanluoyc avatar ethanluoyc commented on May 13, 2024

@tlbtlbtlb I think I can't. In my experiment I am using the visual image data directly as feature input. However, I think there is no other API for me to obtain that other than using render?

from gym.

ahsteven avatar ahsteven commented on May 13, 2024

Hi I just installed gym atari today. And ran the test code for atari:

`import gym

env = gym.make('SpaceInvaders-v0')

env.reset()

env.render()`

The Atar window pops open. however when I try to close with

env.render(close=True)

I get the error:
Traceback (most recent call last):
File "", line 1, in
TypeError: render() got an unexpected keyword argument 'close'

I am on ubuntu 16.04
gym version 0.10.3

from gym.

lcukerd avatar lcukerd commented on May 13, 2024

@cuongqn How do I close it after I interrupt the Kernel? env.close() is written at the end and will not work in case of Kernel interrupt. How do I close the window now?

from gym.

shuruiz avatar shuruiz commented on May 13, 2024

The env.render(close=True) command does not work for me. I got the following error:

TypeError Traceback (most recent call last)
in ()
13 print("Total reward for episode: {}".format(episode_reward))
14 break
---> 15 random_agent(10)

in random_agent(num_episodes)
6
7 for t in range(1000):
----> 8 env.render(close=True)
9 action =env.action_space.sample()
10 observation, reward, done,info = env.step(action)

TypeError: render() got an unexpected keyword argument 'close'

from gym.

eemelipa avatar eemelipa commented on May 13, 2024

@samisnotinsane as a workaround try to add from gym.utils import play to your imports. So run

import gym
from gym.utils import play

#%%

env = gym.make('CartPole-v0')
env.reset()

#%%

for _ in range(1000):
    env.render()
    env.step(env.action_space.sample()) #take a random action

env.close()

where "#%%" is a code cell separation. That helped for me. No idea why, but now the window closes from the cross and with env.close() 🤷

Almost like the plain gym import is missing something relevant for rendering on Mac.

I've got

Mac Os Big Sur      11.5
Python              3.7.11
gym                 0.18.3
jupyter-client      6.1.12
jupyter-console     6.4.0
jupyter-core        4.7.1
ipykernel           5.3.4
ipython             7.22.0

from gym.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.