pythonopenai-gym

Error running code taking from Gymnasium tutorial


I would like to run the following code using PyCharm IDE

import gymnasium as gym
env = gym.make("LunarLander-v2", render_mode="human")
observation, info = env.reset(seed=42)
for _ in range(1000):
   action = env.action_space.sample()  # this is where you would insert your policy
   observation, reward, terminated, truncated, info = env.step(action)

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

env.close()

I got the code from here. I installed "Gymnasium" in my computer using "pip install gymnasium". The Python version I am using is "Python 3.11.5".

ERROR: Failed building wheel for box2d-py Failed to build box2d-py ERROR: Could not build wheels for box2d-py, which is required to install pyproject.toml-based projects" - What will be the solution?


Solution

  • I use the same example in colab, and it gave me the same error. These commands worked for me:

    !pip3 install gymnasium
    !apt-get install build-essential
    !apt-get install swig
    !apt-get install python-box2d
    !pip install gym[box2d]