解决安装强化学习库gymnasium,box2d安装报错的问题

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/

解决安装强化学习库gymnasium,box2d安装报错的问题_第1张图片

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

解决安装强化学习库gymnasium,box2d安装报错的问题_第2张图片

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

 测试代码

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

如果出现该界面,那么就是安装成功啦!

解决安装强化学习库gymnasium,box2d安装报错的问题_第3张图片

参考:Failed building wheel for box2d-py · Issue #3143 · openai/gym (github.com)

你可能感兴趣的:(python,人工智能)