强化学习(二):安装gym.

gymnasium是强化学习的库,比较难安装。

一、安装方法


安装Gymnasium(一定要all,这样可以安装所有依赖)

pip install gymnasium[all]
pip install gymnasium[all]

二、报错信息一:ERROR: Could not build wheels for box2d-py, which is required to install pyproject.toml-based projects


conda install swig
但是解决后还是继续报错。

三、error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/

 

 登录该网站build-tools ,点击下载生成工具。

勾选使用C++的桌面开发,点击安装。

四、安装

pip install gymnasium[all]

conda install swig

五、测试代码

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()

 

posted @ 2024-02-29 12:34  jasonzhangxianrong  阅读(324)  评论(0编辑  收藏  举报