AttributeError: 'TaxiEnv' object has no attribute 's'

AttributeError: 'TaxiEnv' object has no attribute 's'

我正在尝试使用 OpenAI Gym 的 TaxiEnvironment。我编写了以下代码行,但出现以下错误。

import numpy as np
import gym
import random
env = gym.make("Taxi-v3")
env.render()

错误:

AttributeError                            Traceback (most recent call last)
C:\Users\KESABC~1\AppData\Local\Temp/ipykernel_11956/4159949162.py in <module>
      1 env = gym.make("Taxi-v3")
----> 2 env.render()

~\anaconda3\lib\site-packages\gym\core.py in render(self, mode, **kwargs)
    284 
    285     def render(self, mode="human", **kwargs):
--> 286         return self.env.render(mode, **kwargs)
    287 
    288     def close(self):

~\anaconda3\lib\site-packages\gym\core.py in render(self, mode, **kwargs)
    284 
    285     def render(self, mode="human", **kwargs):
--> 286         return self.env.render(mode, **kwargs)
    287 
    288     def close(self):

~\anaconda3\lib\site-packages\gym\envs\toy_text\taxi.py in render(self, mode)
    220         out = self.desc.copy().tolist()
    221         out = [[c.decode("utf-8") for c in line] for line in out]
--> 222         taxi_row, taxi_col, pass_idx, dest_idx = self.decode(self.s)
    223 
    224         def ul(x):

AttributeError: 'TaxiEnv' object has no attribute 's'

我应该怎么做才能消除错误?

代码在 gym 0.19 中有效,但在 0.23 中无效,但真正的问题是您以错误的方式使用它。

您必须在开始时设置默认值 - env.reset() - 它会起作用。

import gym

env = gym.make("Taxi-v3")
env.reset()
env.render()