openai / gym

A toolkit for developing and comparing reinforcement learning algorithms.
https://www.gymlibrary.dev
Other
34.48k stars 8.59k forks source link

AttributeError: 'Box' object has no attribute n #1809

Closed penneShells closed 4 years ago

penneShells commented 4 years ago

I have just started coding ai with gym, im using the gym import and gym_tetris, and i keep getting th error that "AttributeError: 'Box' object has no attribute 'n'". Any explanation would be great, but bear in mind i am pretty new to all this, so you may have to dumb it down a bit! The line that was making the error occur was : env.observation_space.n

christopherhesse commented 4 years ago

Box spaces don't have that property, the code you are using likely requires a discrete observation space. Is the code that is failing in gym, or some other library?

penneShells commented 4 years ago

The code so far was this: from nes_py.wrappers import JoypadSpace import gym_tetris from gym_tetris.actions import MOVEMENT import numpy as np import gym

env = gym.make("TetrisA-v2")

env.reset()

env.observation_space.n

but the tutorial i was using only said i needed gym and when trying only gym with a different environment, the same issue occurred.

The tutorial was: https://www.oreilly.com/radar/introduction-to-reinforcement-learning-and-openai-gym/

christopherhesse commented 4 years ago

That tutorial does env = gym.make("Taxi-v2"), for which that line of code should work. For environments without discrete observation spaces, like the tetris one you mentioned, you'll have to handle those in your code.

You should probably look for a tutorial specifically for gym_tetris or start with gym retro which likely has similar observation spaces (and an example random agent, and training script).