Anaconda安装GYM &关于Box2D安装的相关问题

创建一个对应的环境

conda create -n gym python=3.9

进入环境

conda activate gym

使用pip安装gym

pip install gym

安装pygame(not nessary)

pip install pygame

安装box2d

conda install -c conda-forge box2d-py

测试

1.小车连杆(不需要安装box2d)

import gym
env = gym.make('CartPole-v0')
env.reset()
for i in range(1000):
    env.render()
    env.step(env.action_space.sample()) # take a random action
env.close()
  1. 月球登陆(需要box2d)
import gym
env = gym.make("LunarLander-v2")
env.reset()
env.action_space.seed(42)

observation, info = env.reset(seed=42, return_info=True)

for _ in range(1000):
    env.render(mode='human')
    observation, reward, done, info = env.step(env.action_space.sample())

    if done:
        observation, info = env.reset(return_info=True)

env.close()

官方api文件提供的月球登陆在gym.make(“LunarLander-v2”, render_mode=“human”)这步会报错TypeError: init() got an unexpected keyword argument ‘render_mode’,只得把render单拿出来才能运行成功。

参考

conda-forge / packages / box2d-py
Gym Documentation

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值