服务器跑强化学习pyglet.canvas.xlib.NoSuchDisplayException: Cannot connect to “None“

错误信息:

Traceback (most recent call last): File "ddqn.py", line 212, in next_state, reward, done, info = env.step(action) File "/root/autodl-tmp/wrapper.py", line 126, in step observation, reward, done, info = self.env.step(action) File "/root/miniconda3/lib/python3.8/site-packages/gym/core.py", line 282, in step observation, reward, done, info = self.env.step(action) File "/root/autodl-tmp/wrapper.py", line 414, in step self.env.render() File "/root/miniconda3/lib/python3.8/site-packages/gym/core.py", line 254, in render return self.env.render(mode, **kwargs) File "/root/miniconda3/lib/python3.8/site-packages/gym/core.py", line 254, in render return self.env.render(mode, **kwargs) File "/root/miniconda3/lib/python3.8/site-packages/gym/core.py", line 254, in render return self.env.render(mode, **kwargs) File "/root/miniconda3/lib/python3.8/site-packages/gym/envs/atari/atari_env.py", line 166, in render from gym.envs.classic_control import rendering File "/root/miniconda3/lib/python3.8/site-packages/gym/envs/classic_control/rendering.py", line 27, in from pyglet.gl import * File "/root/miniconda3/lib/python3.8/site-packages/pyglet/gl/__init__.py", line 239, in import pyglet.window File "/root/miniconda3/lib/python3.8/site-packages/pyglet/window/__init__.py", line 1896, in gl._create_shadow_window() File "/root/miniconda3/lib/python3.8/site-packages/pyglet/gl/__init__.py", line 208, in _create_shadow_window _shadow_window = Window(width=1, height=1, visible=False) File "/root/miniconda3/lib/python3.8/site-packages/pyglet/window/xlib/__init__.py", line 166, in __init__ super(XlibWindow, self).__init__(*args, **kwargs) File "/root/miniconda3/lib/python3.8/site-packages/pyglet/window/__init__.py", line 501, in __init__ display = get_platform().get_default_display() File "/root/miniconda3/lib/python3.8/site-packages/pyglet/window/__init__.py", line 1845, in get_default_display return pyglet.canvas.get_display() File "/root/miniconda3/lib/python3.8/site-packages/pyglet/canvas/__init__.py", line 82, in get_display return Display() File "/root/miniconda3/lib/python3.8/site-packages/pyglet/canvas/xlib.py", line 86, in __init__ raise NoSuchDisplayException('Cannot connect to "%s"' % name)pyglet.canvas.xlib.NoSuchDisplayException: Cannot connect to "None"

解决:

  1. sudo apt-get install xvfb

  1. 使用xvfb-run -s "-screen 0 640x480x24" python ./xxxx.py 运行

你可能感兴趣的:(python)