Anwesa Roy
Anwesa Roy

Reputation: 67

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

I am trying to use TaxiEnvironment of OpenAI Gym. I have written the following lines of code and I am getting the following error.

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

Error:

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'

What should I do to remove the error?

Upvotes: 1

Views: 3551

Answers (1)

furas
furas

Reputation: 142681

Code worked in gym 0.19 but not in 0.23 but real problem is that you use it in wrong way.

You have to set default values at start - env.reset() - and it will work.

import gym

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

Upvotes: 6

Related Questions