首页 > 解决方案 > AttributeError:“计时器”对象没有属性“_seed”

问题描述

这是我使用的代码。我在https://github.com/openai/universe#break-down-the-example上找到了这段代码。由于我在远程管理器上遇到错误,所以我必须复制此代码才能运行它。但它仍然给我如下错误

import gym
import universe  # register the universe environments

    env = gym.make('flashgames.DuskDrive-v0')
    env.configure(remotes=1)  # automatically creates a local docker container
    observation_n = env.reset()

    while True:
      action_n = [[('KeyEvent', 'ArrowUp', True)] for ob in observation_n]  # your agent here
      observation_n, reward_n, done_n, info = env.step(action_n)
      env.render()

我在尝试运行上面的脚本时得到了这个。我尝试了所有可能的方法来解决它,但它仍然导致同样的错误。关于这一点甚至没有一个线程。我现在不知道该怎么办,请告诉我是否有人解决了它。

我在 Windows 10 上运行的虚拟机上使用 Ubuntu 18.04 LTS

    WARN: Environment '<class 'universe.wrappers.timer.Timer'>' has deprecated methods '_step' and '_reset' rather than 'step' and 'reset'. Compatibility code invoked. Set _gym_disable_underscore_compat = True to disable this behavior.
Traceback (most recent call last):
  File "gymtest1.py", line 4, in <module>
    env = gym.make("flashgames.CoasterRacer-v0")
  File "/home/mystery/.local/lib/python3.6/site-packages/gym/envs/registration.py", line 167, in make
    return registry.make(id)
  File "/home/mystery/.local/lib/python3.6/site-packages/gym/envs/registration.py", line 125, in make
    patch_deprecated_methods(env)
  File "/home/mystery/.local/lib/python3.6/site-packages/gym/envs/registration.py", line 185, in patch_deprecated_methods
    env.seed  = env._seed
AttributeError: 'Timer' object has no attribute '_seed'

标签: python-3.xdockeropenai-gym

解决方案


所以我认为您需要在Timer 模块中添加几行代码,因为代码会检查代码是否实现了某些功能(_step、_reset、_seed 等...)

所以你需要做的(我认为)就是在 Timer 类的末尾添加:

def _seed(self, seed_num=0): # this is so that you can get consistent results
    pass                     # optionally, you could add: random.seed(random_num)
    return

推荐阅读