pyglet.gl.ContextException: Could not create GL context

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:11
  • Comments:28 (7 by maintainers)

github_iconTop GitHub Comments

34reactions
oarriagacommented, Jul 25, 2019

Hi I had a similar issue and fixed it by looking at which OpenGL version I had by calling:

glxinfo | grep OpenGL
>> OpenGL core profile version string: 3.3 (Core Profile) Mesa 19.1.3

Then I changed in the constants.py file in pyrender.py (you can find it wherever you installed pyrender in my case: ~/.local/lib/python3.7/site-packages/pyrender/constants.py)

OPEN_GL_MAJOR = 3
OPEN_GL_MINOR = 3

After that I was able to render 😃!

7reactions
nicolasugrinoviccommented, Apr 29, 2021

Just for the record, I added:

os.environ['PYOPENGL_PLATFORM'] = 'egl'

to the main script and solved the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ImportError: Error occured while running `from pyglet.gl import ...
You need an older version of pyglet; Installing it via pip should do the trick: pip install pyglet==1.5.11. Further discussion here:.
Read more >
about issue #51 pyglet.gl.ContextException: Could not create ...
I've been getting this issue regualrly on all linux installations while playing with pyglet. I see it's fixed now in the repository but...
Read more >
Creating an OpenGL context — pyglet v2.0.2
When you draw on a window in pyglet, you are drawing to an OpenGL context. Every window has its own context, which is...
Read more >
intermittent 'GL context' error - pyglet-users@googlegroups.com
pyglet.gl.ContextException: Could not create GL context ---- It doesn't happen every time - seems to be about 50% (but not in any discernable...
Read more >
Failed to initialize Pyglet window with an OpenGL >= 3+ context
I ssh-ed into a remote server that has no monitor and got an error when trying to run a script. ValueError: Failed to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found