gpt4 book ai didi

python - OpenAI "gym"库在 env.render() 上引发 NoneType 错误

转载 作者:行者123 更新时间:2023-11-30 09:59:08 25 4
gpt4 key购买 nike

这是我第一次使用机器学习库,我以前都是自己做的,当我做的时候它起作用了,但我想当每个人都告诉你不要自己做这项工作并让库来做的时候你,你最终尝试了,我在Python上尝试了OpenAI的“gym”,我的代码非常简单(我在一个youtube视频上找到了它,它解释了如何使用这个库,因为我不知道我要做什么)

    import gym

env = gym.make("MountainCar-v0")
env.reset()

done = False

while not done:
action = 2
newState, reward, done, _ = env.step(action)
env.render()

env.close()

这段代码返回给我这个错误:

Traceback (most recent call last): File "C:\Users\user\PycharmProjects\TestOnGymLibrary\venv\lib\site-packages\pyglet__init__.py", line 378, in getattr return getattr(self._module, name) AttributeError: 'NoneType' object has no attribute 'get_default'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:/Users/user/PycharmProjects/TestOnGymLibrary/me/RoeeHerzovich/TestOnGymLibrary

/Core.py", line 11, in env.render() File "C:\Users\user\PycharmProjects\TestOnGymLibrary\venv\lib\site-packages\gym\core.py", line 235, in render return self.env.render(mode, **kwargs) File "C:\Users\user\PycharmProjects\TestOnGymLibrary\venv\lib\site-packages\gym\envs\classic_control\mountain_car.py", line 78, in render from gym.envs.classic_control import rendering File "C:\Users\user\PycharmProjects\TestOnGymLibrary\venv\lib\site-packages\gym\envs\classic_control\rendering.py", line 27, in from pyglet.gl import * File "C:\Users\user\PycharmProjects\TestOnGymLibrary\venv\lib\site-packages\pyglet\gl__init__.py", line 239, in import pyglet.window File "C:\Users\user\PycharmProjects\TestOnGymLibrary\venv\lib\site-packages\pyglet\window__init__.py", line 1896, in gl._create_shadow_window() File "C:\Users\user\PycharmProjects\TestOnGymLibrary\venv\lib\site-packages\pyglet\gl__init__.py", line 208, in _create_shadow_window _shadow_window = Window(width=1, height=1, visible=False) File "C:\Users\user\PycharmProjects\TestOnGymLibrary\venv\lib\site-packages\pyglet\window\win32__init__.py", line 134, in init super(Win32Window, self).init(*args, **kwargs) File "C:\Users\user\PycharmProjects\TestOnGymLibrary\venv\lib\site-packages\pyglet\window__init__.py", line 501, in init display = get_platform().get_default_display() File "C:\Users\user\PycharmProjects\TestOnGymLibrary\venv\lib\site-packages\pyglet\window__init__.py", line 1845, in get_default_display return pyglet.canvas.get_display() File "C:\Users\user\PycharmProjects\TestOnGymLibrary\venv\lib\site-packages\pyglet\canvas__init__.py", line 77, in get_display from pyglet.app import displays File "C:\Users\user\PycharmProjects\TestOnGymLibrary\venv\lib\site-packages\pyglet\app__init__.py", line 175, in event_loop = EventLoop() File "C:\Users\user\PycharmProjects\TestOnGymLibrary\venv\lib\site-packages\pyglet\app\base.py", line 119, in init self.clock = clock.get_default() File "C:\Users\user\PycharmProjects\TestOnGymLibrary\venv\lib\site-packages\pyglet__init__.py", line 384, in getattr import(import_name) File "C:\Users\user\PycharmProjects\TestOnGymLibrary\venv\lib\site-packages\pyglet\clock.py", line 166, in _default_time_function = time.clock AttributeError: module 'time' has no attribute 'clock'

我尝试在一些地方寻找这个,但我还没有看到......我安装了gym、matplotlib和pyglet,我检查了它们,甚至尝试--升级它们,它说它已经升级了,所以我不知道发生了什么。有人可以帮我吗?

感谢您的所有评论:)

最佳答案

真正的错误来自您发布的跟踪的底部:

_default_time_function = time.clock AttributeError:模块“时间”没有属性“时钟”

此错误已得到解决 here .

选项:

找到 time.clock() 被调用的地方,并将其更改为 time.perf_counter()

降级至3.7

关于python - OpenAI "gym"库在 env.render() 上引发 NoneType 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59742262/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com