Gym: Unable to import gym on Python 2.7, ImportError: cannot import name spaces.

Created on 31 Jan 2018  Â·  14Comments  Â·  Source: openai/gym

> python --version
Python 2.7.13 :: Anaconda 4.3.1 (x86_64)

I did pip install -U gym to get 0.9.6.

>>> import gym
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/rkn/anaconda2/lib/python2.7/site-packages/gym/__init__.py", line 12, in <module>
    from gym import wrappers, spaces, logger
  File "/Users/rkn/anaconda2/lib/python2.7/site-packages/gym/spaces/__init__.py", line 1, in <module>
    from gym.spaces.box import Box
  File "/Users/rkn/anaconda2/lib/python2.7/site-packages/gym/spaces/box.py", line 2, in <module>
    from gym import Space, spaces, logger
ImportError: cannot import name spaces

Most helpful comment

Fixed

All 14 comments

Related to #838, but that issue pre-dates 0.9.6 so is likely a different problem.

It seems to be a recursive import problem with Python 2. If I replace the __init__.py by the following, it seems to work for me:

import distutils.version
import os
import sys
import warnings

from gym.utils import reraise
from gym.version import VERSION as __version__

from gym.core import Env, Space, Wrapper, ObservationWrapper, ActionWrapper, RewardWrapper
from gym.envs import make, spec
from gym import wrappers, logger

spaces = None
import gym.spaces
from gym import spaces

def undo_logger_setup():
    warnings.warn("gym.undo_logger_setup is deprecated. gym no longer modifies the global logging configuration")

__all__ = ["Env", "Space", "Wrapper", "make", "spec", "wrappers"]

Note I removed the from gym import spaces from above and then first import gym.spaces with gym.spaces set to None and then set gym.spaces to the proper variable.

This might break other things tough, so not sure if it's the right fix.

The problem I mentioned doesn't seem to be reproducible on @pcmoritz's laptop (he has a different problem), so there may be something strange about my setup.

I was doing something wrong, updated the issue description to reflect that.

Same problem here.

Fixed

I encountered the same problem in python 3.5.6 Would you please explain how you solved it?

@fi000 could you post your stack trace?

On Fri, Feb 9, 2018 at 5:40 PM, John Schulman notifications@github.com
wrote:

@fi000 https://github.com/fi000 could you post your stack trace?

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/openai/gym/issues/850#issuecomment-364590213, or mute
the thread
https://github.com/notifications/unsubscribe-auth/Aic3R2XiI4X2MEbhJdU4LlSK6L2sApcdks5tTMlvgaJpZM4R0hk7
.

Please copy and paste the error message that you see when you do import gym.

Hi
I used it for this repository: https://github.com/xenu256/stock_market_reinforcement_learning

When I run, I encounter a problem in gym:
(I clone the latest version of gym but I did not apply the last comment of 2018-01-25)

stock_market_reinforcement_learning-master>python dqn.py portfolio.csv model
Using TensorFlow backend.
WARN: gym.spaces.Box autodetected dtype as . Please provide explicit dtype.
Traceback (most recent call last):
File "dqn.py", line 88, in
sudden_death=-1.0)
File "C:\Users\fi\Desktop\rl\code\3.6\stock_market_reinforcement_learning-master\environment.py", line 43, in __init__
self.reset()
File "C:\Users\fi\Anaconda30\envs\tensorflow\lib\site-packages\gym\core.py", line 70, in reset
raise NotImplementedError
NotImplementedError

import gym
Traceback (most recent call last):
File "", line 1, in
File "gym/__init__.py", line 12, in
from gym import wrappers, spaces, logger
File "gym/spaces/__init__.py", line 1, in
from gym.spaces.box import Box
File "gym/spaces/box.py", line 2, in
from gym import Space, spaces, logger
ImportError: cannot import name spaces

I am encountering same problem. I am using: Python 2.7.12 :: Anaconda 2.0.1 (64-bit)

@fi000

Hello I get the same error:

[33mWARN: gym.spaces.Box autodetected dtype as . Please provide explicit dtype.

Did you fix it?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zhan0903 picture zhan0903  Â·  4Comments

Kallin picture Kallin  Â·  4Comments

Baichenjia picture Baichenjia  Â·  3Comments

cpatyn picture cpatyn  Â·  4Comments

pickittwice picture pickittwice  Â·  4Comments