4

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

Jellyfish
  • 41
  • 1
  • 1
  • 4
  • Can you show us the command line how you want to run the env? – constanze Oct 04 '20 at 10:49
  • 1
    @constanze, I have solved the problem in this way: 1) Downloading swig directory [link](https://sourceforge.net/projects/swig/) 2) extract swig.exe 3) Put swig.exe into the wd of Jupyter notebook in Colab (**content** folder in my case) 4) !pip install BOX2D . Finally Lunar lander works. Did you have another way ? – Jellyfish Oct 05 '20 at 14:42

4 Answers4

8

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!

Trees
  • 1,245
  • 10
  • 20
3
%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

Itay
  • 313
  • 2
  • 3
  • 13
0

Just installing Box2D solved the issue for me

pip install Box2D
Vidya Ganesh
  • 788
  • 11
  • 24
  • 1
    It's important to run `pip install Box2D` BEFORE the first call to `gym.make("LunarLander-v2")`. If you already received this error:`'gym.envs.box2d' has no attribute 'LunarLander'` then you need to factory reset runtime (Runtime -> Factory reset runtime) or create a new notebook. – Dmitriy Work Aug 23 '21 at 12:39
0

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.

Chandan
  • 430
  • 6
  • 9