RL problem on COLAB for 'gym.envs.box2d' has no attribute 'LunarLander'

12.3k Views Asked by At

What can I do in Colab to work with the env "LunarLander-v2" from OPENAI-gym. I have installed BOX2D and box2d-py but always return the same error:

AttributeError: module 'gym.envs.box2d' has no attribute 'LunarLander'

This passage in my local machine works, but on Colab not. What could be a solution ?

Versions: Python:3.6 - Gym:0.17.2 - BOX2D:2.3.10

4

There are 4 best solutions below

2
On

Important part is to create a new Colab notebook, Click on File -> New notebook. On a new (fresh) Colab execute these:

!pip3 install box2d-py
!pip3 install gym[Box_2D]
import gym
env = gym.make("LunarLander-v2")

The gym is installed by default in the new notebook however you have to install the box2d-py and gym[Box_2D]. Please close the current notebook if you have encountered the 'gym.envs.box2d' has no attribute 'LunarLander' error. Simply use a new notebook and go on with above procedure of pip install. It will work!

0
On
%pip install ribs[all] gym~=0.17.0 Box2D~=2.3.10 tqdm
import gym
import time
import numpy as np
import matplotlib.pyplot as plt
from tqdm.notebook import tqdm
env = gym.make("LunarLander-v2")

Should work

1
On

Just installing Box2D solved the issue for me

pip install Box2D
0
On

The error stems from the absence of pybox2d package. Colab or not, does not matter.

The error will appear for any 2d continuous environment.

Install pybox2d by using conda install -c conda-forge pybox2d if you are using Anaconda or by using pip install Box2D if you like pip.

Good luck.