How to fix "Could not create GL context" error [pyrender/trimesh]

I am building a 3d game from scratch on replit for fun in python. I was trying to make a very basic engine using classes to make some built in levels.
Here is my code so far:

import trimesh as tri, pyrender as r, numpy as np, io

class NewScene:
  def __init__(self):
    global scene, camera
    self.scene = r.Scene()
    camera = r.PerspectiveCamera(yfov=np.pi / 3.0, aspectRatio=1.0)
    light = r.SpotLight(color=np.ones(3), intensity=3.0,

    s = np.sqrt(2)/2
    cam_pose = np.array([
       [0.0, -s,   s,   0.3],
       [1.0,  0.0, 0.0, 0.0],
       [0.0,  s,   s,   0.35],
       [0.0,  0.0, 0.0, 1.0],
    self.scene.add(camera, pose=cam_pose)
    self.scene.add(light, pose=cam_pose)
  def LoadNewModel(self, x, y, model, texture=None):   
    newmodel = tri.load(model, force='mesh')
    modelmesh = r.Mesh.from_trimesh(newmodel)
  def RenderScene(self, use_lighting=True, use_prespective=True, win_title="Uni3D Renderer: New Scene"):
    print("scene has been rendered")

  def ExitScene():
    print("scene has ended")

Here is the error I received:

libGL error: MESA-LOADER: failed to open swrast: ��XUU (search paths /nix/store/p36pgcv991mq5srvg765b78yqpxvk3qs-mesa-21.3.3-drivers/lib/dri, suffix _dri)
libGL error: failed to load driver: swrast
Traceback (most recent call last):
  File "", line 8, in <module>
  File "/home/runner/Uni3D/game/coreFiles/", line 15, in Script
  File "/home/runner/Uni3D/game/", line 32, in RenderScene
  File "/home/runner/Uni3D/venv/lib/python3.10/site-packages/pyrender/", line 349, in __init__
  File "/home/runner/Uni3D/venv/lib/python3.10/site-packages/pyrender/", line 1016, in _init_and_start_app
    super(Viewer, self).__init__(config=conf, resizable=True,
  File "/home/runner/Uni3D/venv/lib/python3.10/site-packages/pyglet/window/xlib/", line 133, in __init__
    super(XlibWindow, self).__init__(*args, **kwargs)
  File "/home/runner/Uni3D/venv/lib/python3.10/site-packages/pyglet/window/", line 538, in __init__
    context = config.create_context(gl.current_context)
  File "/home/runner/Uni3D/venv/lib/python3.10/site-packages/pyglet/gl/", line 105, in create_context
    return XlibContext(self, share)
  File "/home/runner/Uni3D/venv/lib/python3.10/site-packages/pyglet/gl/", line 127, in __init__
    raise gl.ContextException('Could not create GL context') Could not create GL context

All help is appreciated! Thanks!

That’s because for some reason Replit’s graphics display doesn’t work.
Also here.

1 Like

That issue was temporary and was resolved shortly after it arose.

I believe this issue is likely a result of not having access to a GPU (which is a power up you can purchase).

I am aware there is a power up, but I do not have the funds for it. Is there any other way I could fix this?

You could try running the script locally on your device?


It returns errors that it can’t find the modules trimesh and pyrender, even though i pip installed them. Even then, I was wondering if there was a way to get it working on replit.

Try using a venv locally

1 Like