pyrender: pyglet.gl.ContextException: Could not create GL context
Hi, Iām trying to run the following code:
import trimesh
import pyrender
tm = trimesh.load('/home/henry/Downloads/fuze.obj')
pymesh = pyrender.Mesh.from_trimesh(tm)
scene = pyrender.Scene()
scene.add(pymesh)
pyrender.Viewer(scene, use_raymond_lighting=True)
And I get the following error:
File "generate_pose_dataset.py", line 172, in mesh_render
pyrender.Viewer(scene, use_raymond_lighting=True)
File "/usr/local/lib/python2.7/dist-packages/pyrender/viewer.py", line 347, in __init__
self._init_and_start_app()
File "/usr/local/lib/python2.7/dist-packages/pyrender/viewer.py", line 995, in _init_and_start_app
height=self._viewport_size[1])
File "/usr/local/lib/python2.7/dist-packages/pyglet/window/xlib/__init__.py", line 170, in __init__
super(XlibWindow, self).__init__(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/pyglet/window/__init__.py", line 595, in __init__
context = config.create_context(gl.current_context)
File "/usr/local/lib/python2.7/dist-packages/pyglet/gl/xlib.py", line 216, in create_context
return XlibContextARB(self, share)
File "/usr/local/lib/python2.7/dist-packages/pyglet/gl/xlib.py", line 322, in __init__
super(XlibContext13, self).__init__(config, share)
File "/usr/local/lib/python2.7/dist-packages/pyglet/gl/xlib.py", line 230, in __init__
raise gl.ContextException('Could not create GL context')
pyglet.gl.ContextException: Could not create GL context
My computer shows that PyOpenGL 3.1.0, PyOpenGL_accelerate 3.1.0, and pyglet appear to be correctly installed.
To test pyglet externally from pyrender, I ran the following code:
import pyglet
pyglet.window.Window()
and a window opens as expected.
Any ideas why this error is occurring?
Iām running 16.04 with 64 bit.
Thanks! Henry C.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 13
- Comments: 33 (7 by maintainers)
Hi I had a similar issue and fixed it by looking at which OpenGL version I had by calling:
Then I changed in the
constants.pyfile in pyrender.py (you can find it wherever you installed pyrender in my case: ~/.local/lib/python3.7/site-packages/pyrender/constants.py)After that I was able to render š!
I still had the problem after re-installing anaconda and creating a new environment but it was fixed by running
conda install -c conda-forge libstdcxx-ng(on Ubuntu 22.04)Just for the record, I added:
os.environ['PYOPENGL_PLATFORM'] = 'egl'to the main script and solved the issue.
I was facing a very similar issue and this was the solution that finally fixed it for me! One small update: in my pyrender/constants.py file, I had to make the changes