Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

pygame window is not shutting down with env.close()

$
0
0

I've been trying to set up the reinforcement learning environment on my local PC (intel mac os), but I've been continuously having an issue with the pygame window. System is not letting me to close the pygame window with the env.close() function.

Here is my main.py.

import osimport gymfrom stable_baselines3 import PPOfrom stable_baselines3.common.vec_env import DummyVecEnvfrom stable_baselines3.common.evaluation import evaluate_policyenv_name = 'CartPole-v1'env = gym.make(env_name, render_mode="human")for episode in range(1, 11):    score = 0    state = env.reset()    done = False    while not done:        env.render()        action = env.action_space.sample()        n_state, reward, done, info, _ = env.step(action)        score += reward    print('Episode:', episode, 'Score:', score)env.close()

I've tested on multiple IDEs and different versions of python, but I'm currently lost about what to do. The only way I was able to turn it off was, restart the kernel on Jupiter Notebook, or re-run the script on pycharm. I'm looking for an advise to resolve this issue.

I was able to obtain the score values without using the render_mode="human", but the display would not show up unless I set the specific render_mode. I'm not quite sure how all the other tutorials on youtube were able to pop up the rendering display.

Here's an output sample of the code from pycharm.

/opt/anaconda3/envs/cartpole/lib/python3.8/site-packages/gym/utils/passive_env_checker.py:233: DeprecationWarning: `np.bool8` is a deprecated alias for `np.bool_`.  (Deprecated NumPy 1.24)  if not isinstance(terminated, (bool, np.bool8)):Episode: 1 Score: 25.0Episode: 2 Score: 21.0Episode: 3 Score: 24.0Episode: 4 Score: 37.0Episode: 5 Score: 33.0Episode: 6 Score: 25.0Episode: 7 Score: 20.0Episode: 8 Score: 22.0Episode: 9 Score: 10.0Episode: 10 Score: 21.0env.close()

Although I've added another env.close() function, pygame window never closes. Please let me know if I'm missing anything. I really appreciate for the help.


Viewing all articles
Browse latest Browse all 23131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>