Jupyter notebook 内核在运行 gym env.render() (MacOS) 时死机

问题描述 投票:0回答:0

编辑:当我删除

render_mode="rgb_array"
时,它工作正常。但这显然不是真正的解决方案。

我正在尝试在 Jupyter notebook 中运行游戏渲染,但每次我运行它时都会弹出一个消息说

Python 3.7 crashed
并且内核已经死了。

%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
import time
import gym
from gym.envs.registration import register
from IPython.display import clear_output

try:
    register(
        id='FrozenLakeNotSlippery-v0', #Name this whatever you want
        entry_point='gym.envs.toy_text:FrozenLakeEnv',
        kwargs={'map_name' : '4x4', 'is_slippery': False},
        max_episode_steps=100,
        reward_threshold=0.78, # optimum = .8196
    ) 
except: 
    print("Already Registered")
    
env = gym.make("FrozenLakeNotSlippery-v0",render_mode='rgb_array')
env.reset()
for step in range(5):
    env.render()
    action = env.action_space.sample()
    observation, reward, terminated, truncated, info = env.step(action)
    time.sleep(0.5)
    print(observation)
    clear_output(wait=True)
    if terminated:
        env.reset()
    
env.close()    

以上是我的代码。它非常简单,似乎是一个已知问题,但我还没有看到任何人有任何解决方案。

我尝试使用 pip install 卸载并重新安装以下软件包:

  • ipy内核
  • ipython
  • jupyter_client
  • jupyter_core
  • 特质
  • ipython_genutils 但我仍然有同样的问题。
python machine-learning jupyter-notebook openai-gym
© www.soinside.com 2019 - 2024. All rights reserved.