5

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'.

Vardan Agarwal
  • 2,023
  • 2
  • 15
  • 27

2 Answers2

6

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.

Vardan Agarwal
  • 2,023
  • 2
  • 15
  • 27
0

I renamed it to gim.py but it is not working the code is:

import gym
env = gym.make("CartPole-v1")
observation, info = env.reset(seed=42)

for _ in range(1000):
    action = env.action_space.sample()
    observation, reward, terminated, truncated, info = env.step(action)

    if terminated or truncated:
        observation, info = env.reset()
env.close()

I did pip install gym

Unkown
  • 1
  • You shouldn't rename it as `gim.py`. – Ynjxsjmh Mar 04 '23 at 04:25
  • If you have a new question, please ask it by clicking the [Ask Question](https://stackoverflow.com/questions/ask) button. Include a link to this question if it helps provide context. - [From Review](/review/late-answers/33965705) – Niklas Mohrin Mar 07 '23 at 21:24
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 09 '23 at 22:00