python - 导入错误 : cannot import 'rendering' from 'gym.envs.classic_control'

标签 python reinforcement-learning openai-gym

我正在与 RL 代理合作,并试图复制这个 paper 的发现,其中他们基于 Gym 开放式 AI 制作自定义跑酷环境,但是在尝试渲染此环境时我遇到了问题。

import numpy as np
import time
import gym
import TeachMyAgent.environments

env = gym.make('parametric-continuous-parkour-v0', agent_body_type='fish', movable_creepers=True)
env.set_environment(input_vector=np.zeros(3), water_level = 0.1)
env.reset()

while True:
    _, _, d, _ = env.step(env.action_space.sample())
    env.render(mode='human')
    time.sleep(0.1)

c:\users\manu dwivedi\teachmyagent\TeachMyAgent\environments\envs\parametric_continuous_parkour.py in render(self, mode, draw_lidars)
    462 
    463     def render(self, mode='human', draw_lidars=True):
--> 464         from gym.envs.classic_control import rendering
    465         if self.viewer is None:
    466             self.viewer = rendering.Viewer(RENDERING_VIEWER_W, RENDERING_VIEWER_H)

ImportError: cannot import name 'rendering' from 'gym.envs.classic_control' (C:\ProgramData\Anaconda3\envs\teachagent\lib\site-packages\gym\envs\classic_control\__init__.py)

  [1]: https://github.com/flowersteam/TeachMyAgent

我认为这可能是这个自定义环境的问题以及作者如何决定呈现它,然而,当我尝试时

from gym.envs.classic_control import rendering

我遇到了同样的错误,github 用户 here建议这可以通过在调用 gym.make() 渲染时添加 rendor_mode='human' 来解决,但这似乎只适用于他们的特定情况。

最佳答案

我(在同学的帮助下)通过将 gym 包降级到 0.21.0 来让它工作。 为此执行命令 pip install gym==0.21.0

更新,来自 Github issue:

基于 https://github.com/openai/gym/issues/2779

这应该是gymgrid的问题,有公开PR:wsgdrfz/gymgrid#1 如果你想使用最新版本的 gym,你可以尝试使用该 PR 的分支(https://github.com/CedricHermansBIT/gymgrid2);你可以使用 pip install gymgrid2

安装它

关于python - 导入错误 : cannot import 'rendering' from 'gym.envs.classic_control' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71973392/

相关文章:

java - jar 到 python 模块

python - GTK3 中的自定义小部件属性

python - 保存 ImageField mongoengine

python - NotFoundError(请参阅上面的回溯): Key Variable not found in checkpoint

python - 使用 openAIgym 渲染时出现奇怪的输出

reinforcement-learning - Gym (openAI) 环境 Action 空间取决于实际状态

python - 如何用Python实现链式操作?

python - DQN 理解输入和输出(层)

python-3.x - 在 GOOGLE COLAB 中运行开放式 AI 健身房时出现 NameError : name 'base' is not defined,

reinforcement-learning - 获取OpenAI Gym环境的名称/ID