I'm trying to run the below code over SSH on a Google Cloud server. I'm using Ubuntu 17.04, python 3.5 (also tried on python 2.7). I'm on a mac, and xquartz seems to be working fine. I can run the non-graphical environments just fine (e.g. Taxi-v2), but the graphical ones give an error when I call env.render().
Per the error message below, I have tried running:
xvfb-run -s "-screen 0 1400x900x24" python3 myscript.py
But I get this error:
xvfb-run: error: Xvfb failed to start
My code:
import gym
env = gym.make("CartPole-v0")
observation = env.reset()
env.render()
Error:
[2017-06-30 05:10:46,618] Making new env: CartPole-v0
AttributeError Traceback (most recent call last)
~/gym/01.test.py in
2 env = gym.make("CartPole-v0")
3 observation = env.reset()
----> 4 env.render()
5 # x = []
6 # for _ in range(1000): # 1000):
/usr/local/lib/python3.5/dist-packages/gym/core.py in render(self, mode, close)
148 elif mode not in modes:
149 raise error.UnsupportedMode('Unsupported rendering mode: {}. (Supported modes for {}: {})'.format(mode, self, modes))
--> 150 return self._render(mode=mode, close=close)
151
152 def close(self):
/usr/local/lib/python3.5/dist-packages/gym/core.py in _render(self, mode, close)
284
285 def _render(self, mode='human', close=False):
--> 286 return self.env.render(mode, close)
287
288 def _close(self):
/usr/local/lib/python3.5/dist-packages/gym/core.py in render(self, mode, close)
148 elif mode not in modes:
149 raise error.UnsupportedMode('Unsupported rendering mode: {}. (Supported modes for {}: {})'.format(mode, self, modes))
--> 150 return self._render(mode=mode, close=close)
151
152 def close(self):
/usr/local/lib/python3.5/dist-packages/gym/envs/classic_control/cartpole.py in _render(self, mode, close)
113
114 if self.viewer is None:
--> 115 from gym.envs.classic_control import rendering
116 self.viewer = rendering.Viewer(screen_width, screen_height)
117 l,r,t,b = -cartwidth/2, cartwidth/2, cartheight/2, -cartheight/2
/usr/local/lib/python3.5/dist-packages/gym/envs/classic_control/rendering.py in
21
22 try:
---> 23 from pyglet.gl import *
24 except ImportError as e:
25 reraise(prefix="Error occured while running from pyglet.gl import *",suffix="HINT: make sure you have OpenGL install. On Ubuntu, you can run 'apt-get install python-opengl'. If you're running on a server, you may need a virtual frame buffer; something like this should work: 'xvfb-run -s "-screen 0 1400x900x24" python
/usr/local/lib/python3.5/dist-packages/pyglet/gl/__init__.py in
234 # trickery is for circular import
235 _pyglet.gl = _sys.modules[__name__]
--> 236 import pyglet.window
/usr/local/lib/python3.5/dist-packages/pyglet/window/__init__.py in
1814 if not _is_epydoc:
1815 pyglet.window = sys.modules[__name__]
-> 1816 gl._create_shadow_window()
/usr/local/lib/python3.5/dist-packages/pyglet/gl/__init__.py in _create_shadow_window()
203
204 from pyglet.window import Window
--> 205 _shadow_window = Window(width=1, height=1, visible=False)
206 _shadow_window.switch_to()
207
/usr/local/lib/python3.5/dist-packages/pyglet/window/xlib/__init__.py in __init__(self, args, *kwargs)
161 self._event_handlers[message] = func
162
--> 163 super(XlibWindow, self).__init__(args, *kwargs)
164
165 global _can_detect_autorepeat
/usr/local/lib/python3.5/dist-packages/pyglet/window/__init__.py in __init__(self, width, height, caption, resizable, style, fullscreen, visible, vsync, display, screen, config, context, mode)
502 None]:
503 try:
--> 504 config = screen.get_best_config(template_config)
505 break
506 except NoSuchConfigException:
/usr/local/lib/python3.5/dist-packages/pyglet/canvas/base.py in get_best_config(self, template)
159 pass
160 else:
--> 161 configs = self.get_matching_configs(template)
162 if not configs:
163 raise window.NoSuchConfigException()
/usr/local/lib/python3.5/dist-packages/pyglet/canvas/xlib.py in get_matching_configs(self, template)
177 def get_matching_configs(self, template):
178 canvas = XlibCanvas(self.display, None)
--> 179 configs = template.match(canvas)
180 # XXX deprecate
181 for config in configs:
/usr/local/lib/python3.5/dist-packages/pyglet/gl/xlib.py in match(self, canvas)
27
28 info = glx_info.GLXInfo(x_display)
---> 29 have_13 = info.have_version(1, 3)
30 if have_13:
31 config_class = XlibCanvasConfig13
/usr/local/lib/python3.5/dist-packages/pyglet/gl/glx_info.py in have_version(self, major, minor)
84
85 server_version = self.get_server_version().split()[0]
---> 86 client_version = self.get_client_version().split()[0]
87
88 server = [int(i) for i in server_version.split('.')]
/usr/local/lib/python3.5/dist-packages/pyglet/gl/glx_info.py in get_client_version(self)
116 def get_client_version(self):
117 self.check_display()
--> 118 return asstr(glXGetClientString(self.display, GLX_VERSION))
119
120 def get_client_extensions(self):
/usr/local/lib/python3.5/dist-packages/pyglet/compat.py in asstr(s)
86 if isinstance(s, str):
87 return s
---> 88 return s.decode("utf-8")
89
90 bytes_type = bytes
AttributeError: 'NoneType' object has no attribute 'decode'
I ran into this issue a while back.
This fixed it for me:
export DISPLAY=':99.0'
Xvfb :99 -screen 0 1400x900x24 > /dev/null 2>&1 &
Let me know if it worked 🙂
Cheers
D
I have the same issue. https://github.com/openai/gym/issues/735
and I solved it by using fake screen
See this for details.
https://github.com/2017-fall-DL-training-program/Setup_tutorial/blob/master/OpenAI-gym-install.md
Yeah I submitted an issue a while back, describing the same observation. That said - for debugging reasons, it'd be nice to actually see what's going on 😄
Am 27.10.2017 um 02:55 schrieb Wei Li <[email protected]notifications@github.com>:
I have the same issue. #735https://github.com/openai/gym/issues/735
and I solved it by using fake screen
See this for details.
https://github.com/2017-fall-DL-training-program/Setup_tutorial/blob/master/OpenAI-gym-install.md
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHubhttps://github.com/openai/gym/issues/637#issuecomment-339842144, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AHHuNVy8yQx3HBEFU9JOHJ68u_fSkW9bks5swSnygaJpZM4OKKHU.
So I've been following the installation procedure as mentioned above on https://github.com/2017-fall-DL-training-program/Setup_tutorial/blob/master/OpenAI-gym-install.md
But I keep getting the following issues when I run anydesk:
No UTF-8. Trying to change locale.
Locale sucessfully changed.
No protocol specified
(anydesk:11313): Gtk-WARNING **: cannot open display: :0
No UTF-8. Trying to change locale.
Locale sucessfully changed.
No protocol specified
(anydesk:11315): Gtk-WARNING **: cannot open display: :0
No protocol specified
Did you guys have to deal with this too?
You should call
env.close()
before the end of the script.
Like so:
import gym
env = gym.make("CartPole-v0")
observation = env.reset()
env.render()
env.close()
I met a similar problem caused by
from pyglet.gl import *
in rendering.py, which can be fixed by adding the following lines at top of my code:
# Fix `from pyglet.gl import *` error on Mac OS
import os
os.environ['DYLD_FALLBACK_LIBRARY_PATH'] = '/lib:/usr/lib:/usr/bin/lib:/' + os.environ['DYLD_FALLBACK_LIBRARY_PATH'];
####
It seems that pyglet miss the default system library path on Mac OS.
According to the answer above, I have fixed it by adding /lib:/usr/lib:/usr/bin/lib:/ into environment variables:
vim .zshrc
export DYLD_FALLBACK_LIBRARY_PATH=/lib:/usr/lib:/usr/bin/lib:/Users/hzzone/anaconda3/lib/:$DYLD_FALLBACK_LIBRARY_PATH
So I don't need add above lines repeatedly.
System: macOS.
The original problem appears to be an issue with xvfb-run, not with gym. If there are any other rendering issues which are not local mis-configurations, please file a new issue.
from pyglet.gl import * error on Mac OSimport os
os.environ['DYLD_FALLBACK_LIBRARY_PATH'] = '/lib:/usr/lib:/usr/bin/lib:/' + os.environ['DYLD_FALLBACK_LIBRARY_PATH'];
This is not solving my problem....any other solutions?
Thanks in advance.
Most helpful comment
I ran into this issue a while back.
This fixed it for me:
Let me know if it worked 🙂
Cheers
D