解决:强化学习FrozenLake代码出现KeyError: ‘FrozenLake-v0‘错误、 Consider using IPython.display.IFrame instead错误

问题:

在学习强化学习时,出现**KeyError: ‘FrozenLake-v0’**错误

具体信息如下:
Traceback (most recent call last):
File “D:\InstallPosition\python3.7.3\lib\site-packages\gym\envs\registration.py”, line 158, in spec
return self.env_specs[id]
KeyError: ‘FrozenLake-v0’

Traceback (most recent call last):
  File "D:\registration.py", line 158, in spec
    return self.env_specs[id]
KeyError: 'FrozenLake-v0'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/test.py", line 7, in <module>
    env = gym.make("FrozenLake-v0")
  File "D:\registration.py", line 235, in make
    return registry.make(id, **kwargs)
  File "D:\registration.py", line 128, in make
    spec = self.spec(path)
  File "D:\registration.py", line 187, in spec
    id, matching_envs
gym.error.DeprecatedEnv: Env FrozenLake-v0 not found (valid versions include ['FrozenLake-v1'])

进程已结束,退出代码 1

原因及解决措施:

后来查了查,原因很简单,只是FrozenLake-v0的版本问题,原来的v0版本没有了,现在改为-v1即可,即:FrozenLake-v1。在源代码处改完了,代码立即没有问题了~~开森森(o゚▽゚)o ヾ(✿゚▽゚)ノ

附部分正确代码如下:

import gym
import random

env = gym.make("FrozenLake-v1")
env.reset()
env.render()

action_size = env.action_space.n
state_size = env.observation_space.n

有兴趣的童鞋们赶紧试一试吧!(๑>ڡ<)☆

NOTE:

部分FrozenLake代码中还导入了依赖:

from IPython.display import HTML
HTML('')

出现错误如下:

UserWarning: Consider using IPython.display.IFrame instead
  warnings.warn("Consider using IPython.display.IFrame instead")

这个报错不要紧,很有可能就是开源代码做广告的,注释掉就好咯~~有兴趣的童鞋可以告诉我如果想要保留,报错应该如何解决呢?欢迎大家交流!

你可能感兴趣的:(python,pycharm,强化学习)