baselines icon indicating copy to clipboard operation
baselines copied to clipboard

ImportError: cannot import name 'FlattenObservation'

Open SHYang1210 opened this issue 4 years ago • 7 comments

After I installed it according to the requirements, I got an ImportError: cannot import name 'FlattenObservation' error. I know that it is the version of the gym package or something went wrong elsewhere. Thanks for the help! File "/home/xxx/baselines/baselines/run.py", line 12, in from baselines.common.cmd_util import common_arg_parser, parse_unknown_args, make_vec_env, make_env File "/home/xxx/baselines/baselines/common/cmd_util.py", line 12, in from gym.wrappers import FlattenObservation, FilterObservation ImportError: cannot import name 'FlattenObservation'

SHYang1210 avatar Dec 16 '19 12:12 SHYang1210

pip3 show gym What version do you see?

I got the same error, you can fix it by installing 0.15.4: pip3 install gym==0.15.4

MatPoliquin avatar Dec 19 '19 03:12 MatPoliquin

I'm getting the same issue and my gym version is 0.15.4... any other recommended fixes?

yemam3 avatar Jan 09 '20 23:01 yemam3

I am also getting the same issue with 0.15.4. Any help?

ryanmaxwell96 avatar Jun 27 '20 23:06 ryanmaxwell96

So I'm not sure if this is the answer, but upon looking into the gym/gym/wrappers, folder, it looks like there are only files named "flatten_ovservation" and "filter_observation" so I just chose to import the entire wrappers folder with:

from gym import wrappers

in the cmd_util.py file to get beyond this error. Of course now I get a new error though: File "baselines/common/retro_wrappers.py", line 202 def make_retro(*, game, state=None, max_episode_steps=4500, **kwargs): ^ SyntaxError: invalid syntax

ryanmaxwell96 avatar Jun 28 '20 00:06 ryanmaxwell96

https://github.com/openai/baselines/commit/9ee399f5b20cd70ac0a871927a6cf043b478193f Check your gym version first, the package is modified after 0.15.4, you can check the link above, you can reduce your gym version, use the previous package

SHYang1210 avatar Jun 28 '20 01:06 SHYang1210

So what if we have 0.15.4 already? go even earlier?

ryanmaxwell96 avatar Jun 28 '20 22:06 ryanmaxwell96

I was finally able to get it to work, though with gym 0.15.3 not 0.15.4. Also, I had to remove two underscores in the run.py.

ryanmaxwell96 avatar Jun 29 '20 18:06 ryanmaxwell96