如何在Google Colab中安装和运行Gym Box2D环境?

时间:2019-11-05 14:28:06

标签: python-3.x google-colaboratory openai-gym

我遵循this method来运行box2d环境而不在Google colab中进行渲染,

!apt-get install python-box2d
!pip install box2d-py
!pip install gym[Box_2D]
import gym
env = gym.make("BipedalWalker-v2")

但它显示了这一点

Reading package lists... Done
Building dependency tree       
Reading state information... Done
python-box2d is already the newest version (2.3.2~dfsg-2).
0 upgraded, 0 newly installed, 0 to remove and 28 not upgraded.
Requirement already satisfied: box2d-py in /usr/local/lib/python3.6/dist-packages (2.3.8)
Requirement already satisfied: gym[Box_2D] in /usr/local/lib/python3.6/dist-packages (0.15.3)
  WARNING: gym 0.15.3 does not provide the extra 'box_2d'
Requirement already satisfied: six in /usr/local/lib/python3.6/dist-packages (from gym[Box_2D]) (1.12.0)
Requirement already satisfied: pyglet<=1.3.2,>=1.2.0 in /usr/local/lib/python3.6/dist-packages (from gym[Box_2D]) (1.3.2)
Requirement already satisfied: numpy>=1.10.4 in /usr/local/lib/python3.6/dist-packages (from gym[Box_2D]) (1.17.3)
Requirement already satisfied: scipy in /usr/local/lib/python3.6/dist-packages (from gym[Box_2D]) (1.3.1)
Requirement already satisfied: cloudpickle~=1.2.0 in /usr/local/lib/python3.6/dist-packages (from gym[Box_2D]) (1.2.2)
Requirement already satisfied: future in /usr/local/lib/python3.6/dist-packages (from pyglet<=1.3.2,>=1.2.0->gym[Box_2D]) (0.16.0)

---------------------------------------------------------------------------

AttributeError                            Traceback (most recent call last)

<ipython-input-10-62ca95674145> in <module>()
      3 get_ipython().system('pip install gym[Box_2D]')
      4 import gym
----> 5 env = gym.make("BipedalWalker-v2")

3 frames

/usr/local/lib/python3.6/dist-packages/gym/envs/registration.py in load(name)
     16     mod_name, attr_name = name.split(":")
     17     mod = importlib.import_module(mod_name)
---> 18     fn = getattr(mod, attr_name)
     19     return fn
     20 

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

我还尝试从pip pip install Box2D安装此box2d,但未将其安装在colab中。我们如何在Google Colag中安装和运行box2d健身房环境?

2 个答案:

答案 0 :(得分:1)

请创建一个新的 Colab notebook,点击 File -> New notebook。在一个新的(新鲜的)Colab 上执行这些:

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

新笔记本中默认安装了gym,但是您必须安装box2d-py 和gym[Box_2D]。如果您遇到错误,请关闭当前笔记本。只需使用一个新笔记本(非常重要)并继续上述 pip install 过程。它会起作用!

答案 1 :(得分:0)

我能够与!pip3 install box2d-py==2.3.8一起使用。