Search code examples
pythonopenai-gym

Getting error: module 'gym' has no attribute 'make'


I am trying to run a basic OpenAI-gym program available on their OpenAI-gym's official documentation:

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()

But the program outputs the following error:

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


Solution

  • I figured out that I had named my python file as gym.py which is not allowed and was giving the error. All that needed to be done was to delete that file and name it something else like gym_test.py and then it ran fine.