运行来自 Gymnasium 教程的代码时出错

问题描述 投票:0回答:1

我想使用 PyCharm IDE 运行以下代码

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

我从这里获得了代码。我使用“pip installgymnasium”在计算机中安装了“Gymnasium”。我使用的Python版本是“Python 3.11.5”。

错误:box2d-py 的构建轮子失败 构建 box2d-py 失败 错误:无法为 box2d-py 构建轮子,这是安装基于 pyproject.toml 的项目所必需的” - 解决方案是什么?

python openai-gym
1个回答
0
投票

您在尝试安装“box2d-py”软件包时似乎遇到了错误,该软件包是“gymnasium”软件包的依赖项。该错误消息表明构建“box2d-py”包时出现问题。

  1. 确保您的系统上安装了必要的构建工具。在 Linux 上,您可以使用包管理器安装它们。例如,在 Ubuntu 上,您可以运行命令

    sudo apt-get install build-essential
    。在 macOS 上,您可以通过运行
    xcode-select --install
    安装 Xcode 命令行工具。

  2. 尝试使用以下命令单独安装“box2d-py”包:

    pip install box2d-py
    

    如果安装失败,您可能需要安装特定于您的操作系统的其他依赖项。例如,在 Ubuntu 上,您可以在重试安装之前运行

    sudo apt-get install swig

  3. 成功安装“box2d-py”软件包后,您可以尝试使用以下命令再次安装“gymnasium”软件包:

    pip install gymnasium
    
© www.soinside.com 2019 - 2024. All rights reserved.