【发布时间】:2025-09-21 18:10:02
【问题描述】:
我正在尝试在 Google Colab 环境中使用 OpenAI 健身房来使用强化学习 tutorial。我正在使用创建虚拟显示的策略,然后使用 matplotlib 显示正在渲染的环境。
这在我使用“CartPole-v0”或“LunarLander-v2”环境时效果很好,但在我使用“Taxi-v3”环境时会出错。
笔记本单元格如下:
# install required system dependencies
!apt-get install -y xvfb x11-utils > /dev/null
!pip install gym[box2d] pyvirtualdisplay PyOpenGL PyOpenGL-accelerate > /dev/null
import pyvirtualdisplay
_display = pyvirtualdisplay.Display(visible=False,size=(1400, 900)) # use False with Xvfb
_ = _display.start()
!echo $DISPLAY
import gym
import matplotlib.pyplot as plt
import numpy as np
from IPython import display
env = gym.make("Taxi-v3").env
#env = gym.make("CartPole-v0").env
#env = gym.make('LunarLander-v2')
env.reset()
fig, ax = plt.subplots(figsize=(20, 10))
ax.axis('off')
img = ax.imshow(env.render(mode='rgb_array'))
#img.set_data(env.render(mode='rgb_array'))
display.display(plt.gcf())
display.clear_output(wait=True)
错误如下:
Exception in callback BaseAsyncIOLoop._handle_events(18, 1)
handle: <Handle BaseAsyncIOLoop._handle_events(18, 1)>
Traceback (most recent call last):
File "/usr/lib/python3.6/asyncio/events.py", line 145, in _run
self._callback(*self._args)
-------- ------- ---- etc etc
File "/usr/local/lib/python3.6/dist-packages/ipykernel/iostream.py", line 339, in flush
if self.pub_thread.thread.is_alive():
AttributeError: 'NoneType' object has no attribute 'thread'
如前所述,该错误仅在我使用 Taxi-v3 环境时发生。我有两个问题
- 我应该做哪些更改才能使 Taxi-v3 环境在 Colab 中正常工作?
- Taxi 环境和其他两个环境之间有什么区别?出现此错误的原因可能是什么?
欢迎任何指导或建议。
【问题讨论】:
-
也适用于“MountainCarContinuous-v0”和“Acrobot-v1”环境,但不适用于 Taxi-v3
标签: google-colaboratory reinforcement-learning openai-gym