Gym: AttributeError: module 'gym' has no attribute 'make'

Created on 7 Jun 2016  路  34Comments  路  Source: openai/gym

>>> import gym
>>> env = gym.make('Copy-v0')
Traceback (most recent call last):
  File "<pyshell#5>", line 1, in <module>
    env = gym.make('Copy-v0')
AttributeError: module 'gym' has no attribute 'make'
>>> 

I wanna Why @jonasschneider

Most helpful comment

I was able to reproduce this issue by naming my file gym.py and running:

import gym
env = gym.make('CartPole-v0')

Renaming my file gym-test.py and re-running did not produce the same error.

All 34 comments

That's.. strange? How did you install gym (i.e. through pip or through cloning the repo?)
Please try pip install-ing directly, and also post the output of gym.__file__

>>> import sys
>>> sys.path.append('/Users/jiachen215')
>>> import gym
Traceback (most recent call last):
  File "<pyshell#3>", line 1, in <module>
    import gym
  File "/Users/jiachen215/gym/gym/__init__.py", line 34, in <module>
    from gym.core import Env, Space
  File "/Users/jiachen215/gym/gym/core.py", line 6, in <module>
    from gym import error, monitoring
  File "/Users/jiachen215/gym/gym/monitoring/__init__.py", line 1, in <module>
    from gym.monitoring.monitor import Monitor, load_results, _open_monitors
  File "/Users/jiachen215/gym/gym/monitoring/monitor.py", line 12, in <module>
    from gym.monitoring import stats_recorder, video_recorder
  File "/Users/jiachen215/gym/gym/monitoring/video_recorder.py", line 11, in <module>
    import six.moves.urllib as urlparse
ImportError: No module named 'six.moves.urllib'; 'six.moves' is not a package
>>> 

Ok ~I did as what you said.But I met another problem~

It looks like you're missing the six package (pip install six). We should add that to gym requirements

Actually I just checked and it's already there; can you post the exact pip commands you used to install gym?

Same here. Python 3.5.1.

pip install gym

Running first example from docs and...

AttributeError: module 'gym' has no attribute 'make'

The error remains if starting python console and importing gym, since it loads the file random.py anyway. :/

I found a workaround: I tried renaming the file with the example: random.py to _r.py and then it works. I got the idea from this forum link.

I do not know if it is the expected behaviour of having a file called random.py. I tested calling the file numbers.py and importing numpy from a python console and also it reports a something has no foo method error.

@robermorales I'm slightly confused about why random.py is involved. It sounds like your version of gym did not install correctly; if you're willing to debug, can you try reinstalling via pip and posting the log?

I was able to reproduce this issue by naming my file gym.py and running:

import gym
env = gym.make('CartPole-v0')

Renaming my file gym-test.py and re-running did not produce the same error.

You must have another file called gym.py it gym.pyc in your search path. Running Python with -v will show what files it is loading.

any updates @robermorales @harvitronix?

Running with -v shows that import gym is loading gym.pyc from .

[rober@gurb ai-algorithms]$ python2 -v gym.py 2> errors.txt
[rober@gurb ai-algorithms]$ grep gym errors.txt 
# /home/rober/dev/git/ai-algorithms/gym.pyc matches /home/rober/dev/git/ai-algorithms/gym.py
import gym # precompiled from /home/rober/dev/git/ai-algorithms/gym.pyc
  File "gym.py", line 1, in <module>
    import gym
  File "/home/rober/dev/git/ai-algorithms/gym.py", line 6, in <module>
    env = gym.make( 'CartPole-v0' )

and error persists...

[rober@gurb ai-algorithms]$ grep make errors.txt 
    env = gym.make( 'CartPole-v0' )
AttributeError: 'module' object has no attribute 'make'

I think that, since sys.path contains the empty string as the first entry, import gym try to load ./gym.py instead of the library file. I do not know if it is the expected behaviour, or not.

In Python, you can't call your script gym.py and also load a module called gym. (Actually you can if you set things up right, but it's tricky). Rename gym.py it to something else (like my_clever_alg.py), and delete gym.pyc (a cached compiled version).

The problem is the same calling the file random.py, numbers.py, and other names, only tested if importing gym or numpy. In a file without imports, there is no problem.

@robermorales, are you still experiencing this problem?

@jietang I think that trying to import gym in a directory which contains a file called gym.py is expected to fail. It is an issue that does not need to be solved, but only explained. Same with numbers.py in the case of numpy, etc. Thanks.

Same problem, and solved according to @robermorales suggestion.

similar problem here that I have my first file named copy.py, and then everything stopped working until I realize that my copy.py was called all the time. Then it became clear that copy.py must have existed somewhere else...

Same problem here. I followed @harvitronix suggestion changed my gym.py to open-gym.py and problem solved :+1:

as a newbie, facing this problem while there are two folders of gym which one of the main gym function folder inside the setup gym folder and this cause "the module 'gym' has no attribute 'make'".

After deleted the setup gym folder and remain only gym function folder in default working directory the problem solve.

If you name the file "retro.py" then python will confuse your file with the actual module. Try renaming your file to something else.

when I try and install "pip install -e .[all]", I get this error:

"Unable to execute 'make build -C atari_py/ale_interface -j 3'. HINT: are you sure make is installed?
error: [WinError 2] The system cannot find the file specified"

I'm really frustrated please help...

you should buy nanso_py kit to solve it

I had this error as a consequence of naming my python file: retro.py. After changing the name to game.py it seemed to work fine.

I had the same problem and its solved . Thank you @robermorales

I moved gym.py to a folder and solved.
mkdir sample
mv gym.py sample
python gym.py

Trying to run OpenAI Universe on Raspberry Pi. My first three lines are:
import universe
import gym
env = gym.make('flashgames.NeonRace-v0')

I get an error from Python 3.4.2 Shell "Attribute Error: 'module' object had no attribute 'make'"
the gym folder is located: $HOME/gym/gym

I have been reading all the posts I can find for the last 4 hours and no luck. Any ideas?

Thanks, Lloyd

Thank you @tlbtlbtlb
Your suggestion works for me.

when AttributeError: module 'gym' has no attribute 'make' came then follow the simple two steps
1 - Go to computer to home to user directory and search gym.py file and change the name of this file like any things "Open-gym.py".
2- Search the gym.pyc file and delete it.
It works for me thank you

In Python, you can't call your script gym.py and also load a module called gym. (Actually you can if you set things up right, but it's tricky). Rename gym.py it to something else (like my_clever_alg.py), and delete gym.pyc (a cached compiled version).

This worked for me. Thanks ..@tlbtlbtlb

This bug still exists. But I also found a solution for the same. I am documenting it to help others, if they face similar issue.

$  git clone https://github.com/openai/gym.git
$ cd gym
$ pip install -e .
$ cd -
# to reproduce this bug. we will move the gym directory to a new folder called test which we just created one level above gym.
$ mkdir test
$ mv gym test/

create a file with the example code.

$ cat test_gym.py
import gym
env = gym.make("CartPole-v1")
observation = env.reset()
for _ in range(1000):
  env.render()
  action = env.action_space.sample() # your agent here (this takes random actions)
  observation, reward, done, info = env.step(action)

  if done:
    observation = env.reset()
env.close()

and the error

$ python test_gym.py 
Traceback (most recent call last):
  File "test.py", line 2, in <module>
    env = gym.make("CartPole-v1")
AttributeError: module 'gym' has no attribute 'make'

Problem:

If you move the gym parent directory around. We get the error as shown above.

Solution:

Whenever you move the built directory of gym around to a different location. Then you need to run the install command again in the new directory.

$ cd test/gym
$ pip install -e .

This will fix the problem.

gym.py does not exist for me...

The error remains if starting python console and importing gym, since it loads the file random.py anyway. :/

I found a workaround: I tried renaming the file with the example: random.py to _r.py and then it works. I got the idea from this forum link.

I do not know if it is the expected behaviour of having a file called random.py. I tested calling the file numbers.py and importing numpy from a python console and also it reports a something has no foo method error.

Thank you very much! I finally solve the error by just change a name. That's strange!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lbbc1117 picture lbbc1117  路  3Comments

RuofanKong picture RuofanKong  路  3Comments

mdavis-xyz picture mdavis-xyz  路  3Comments

reaIws picture reaIws  路  4Comments

Ettrig picture Ettrig  路  3Comments