gym渲染画面报错汇总与解决

环境

window10+python3.8+pycharm2023

一、1.安装Box2d报错问题汇总

问题1:error: command ‘swig.exe’ failed: None

在这里插入图片描述

解决办法:
·升级pip

 pip install --upgrade pip
 pip install --upgrade setuptools
 pip install ez_setup

·手动安装swig

pip install swig 

问题2: 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/ error:Could not build wheels for box2d-py, which is required to install pyproject.toml-based projects

在这里插入图片描述
在这里插入图片描述

解决办法:下载安装最新vs,
·下载地址:

https://visualstudio.microsoft.com/visual-cpp-build-tools/

勾选三个生成工具(少了可能不成功),可以自定义安装地址
在这里插入图片描述
·安装成功后输入指令

pip install gymnasium[all]

成功
在这里插入图片描述

CartPole用例警告

1.第一个警告:

UserWarning: WARN: The environment CartPole-v0 is out of date. You should consider upgrading to version `v1`.

解决:将CartPole-v0改成CartPole-v1

2.第二个警告:

DeprecationWarning: `np.bool8` is a deprecated alias for `np.bool_`.  (Deprecated NumPy 1.24)   if not isinstance(terminated, (bool, np.bool8)):

解决:添加import numpy as np

3.第三个警告:

UserWarning: WARN: You are calling 'step()' even though this environment has already returned terminated = True. You should always call 'reset()' once you receive 'terminated = True' -- any further steps are undefined behavior.

解决:增加reset代码

4.第四个警告:

UserWarning: WARN: You are calling render method without specifying any render mode. You can specify the render_mode at initialization, e.g. gym("CartPole-v0", render_mode="rgb_array")

解决:修改为gym(“CartPole-v1”, render_mode=“rgb_array”)
完整代码如下:

import time

import gym           #导入gym的python接口环境包
import numpy as np

env = gym.make('CartPole-v1', render_mode="human")
state = env.reset()
for episode in range(10):
    env.reset()
    for t in range(100):
        env.render()
        print(state)

        action = env.action_space.sample()
        state, reward, done, info, _ = env.step(action)

        if done:
            print('Finished')
            break
        time.sleep(0.02)
env.close()

结果:成功
在这里插入图片描述

  • 20
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值