Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

module 'pyglet.gl' has no attribute 'xlib' #117

Closed
cosw0t opened this issue May 22, 2020 · 7 comments
Closed

module 'pyglet.gl' has no attribute 'xlib' #117

cosw0t opened this issue May 22, 2020 · 7 comments

Comments

@cosw0t
Copy link
Contributor

cosw0t commented May 22, 2020

With the new version 0.1.40 on windows (and possibly macOS, haven't tested) the offscreen renderer fails with:

Traceback (most recent call last):
  File "[...]/scratch_1.py", line 18, in <module>
    renderer.render(scene)
  File "C:\tools\Anaconda3\envs\tra-sim-datacollection\lib\site-packages\pyrender\offscreen.py", line 109, in render
    self._platform.make_uncurrent()
  File "C:\tools\Anaconda3\envs\tra-sim-datacollection\lib\site-packages\pyrender\platforms\pyglet_platform.py", line 54, in make_uncurrent
    pyglet.gl.xlib.glx.glXMakeContextCurrent(self._window.context.x_display, 0, 0, None)
AttributeError: module 'pyglet.gl' has no attribute 'xlib'

Process finished with exit code 1

Old versions <= 0.1.39 were fine

Sample code:

from pyrender import Mesh, Scene, OffscreenRenderer, PerspectiveCamera, RenderFlags
from io import BytesIO
import numpy as np
import trimesh
import requests

duck_source = "https://github.com/KhronosGroup/glTF-Sample-Models/raw/master/2.0/Duck/glTF-Binary/Duck.glb"

duck = trimesh.load(BytesIO(requests.get(duck_source).content), file_type='glb')
duckmesh = Mesh.from_trimesh(list(duck.geometry.values())[0])
scene = Scene(ambient_light=np.array([1.0, 1.0, 1.0, 1.0]))
scene.add(duckmesh)

camera = PerspectiveCamera(60)
scene.add(camera)

renderer = OffscreenRenderer(640, 480)
renderer.render(scene)
@mariabauza
Copy link

We are having the same issue

@cosw0t
Copy link
Contributor Author

cosw0t commented Jun 15, 2020

any input on this @mmatl ?

@ccuetoh
Copy link

ccuetoh commented Jun 17, 2020

Changing line 53 in pyglet_platform.py to import pyglet.gl.xlib seems to fix it. I have a terrible internet connection so I'm unable to make a pull request, but feel free to make it yourself.

@cosw0t
Copy link
Contributor Author

cosw0t commented Jun 17, 2020

Thanks for the advice, however this now results in another error:

  File "C:\tools\Anaconda3\envs\python_utils\lib\site-packages\pyrender\platforms\pyglet_platform.py", line 53, in make_uncurrent
    import pyglet.gl.xlib
  File "C:\tools\Anaconda3\envs\python_utils\lib\site-packages\pyglet\gl\xlib.py", line 40, in <module>
    from pyglet.canvas.xlib import XlibCanvas
  File "C:\tools\Anaconda3\envs\python_utils\lib\site-packages\pyglet\canvas\xlib.py", line 43, in <module>
    from . import xlib_vidmoderestore
  File "C:\tools\Anaconda3\envs\python_utils\lib\site-packages\pyglet\canvas\xlib_vidmoderestore.py", line 54, in <module>
    from pyglet.libs.x11 import xlib
  File "C:\tools\Anaconda3\envs\python_utils\lib\site-packages\pyglet\libs\x11\xlib.py", line 53, in <module>
    _lib = pyglet.lib.load_library('X11')
  File "C:\tools\Anaconda3\envs\python_utils\lib\site-packages\pyglet\lib.py", line 164, in load_library
    raise ImportError('Library "%s" not found.' % names[0])
ImportError: Library "X11" not found.

Process finished with exit code 1

I think xlib is not meant to be used in Windows in the first place

@ccuetoh
Copy link

ccuetoh commented Jun 17, 2020

Yup, it looks like you're right: XLib is not meant to be used on Windows. Looking at all the other pyglet.gl.xlib calls they are all done using a try block as they may be unsupported. I must say though that I'm a complete noob on XLib, so don't take my word for it.

As far as I can see make_uncurrent() is a cleanup operation to allow for multi-threading. If you don't care for it you can give it the same try-block treatment as other xlib calls:

def make_uncurrent(self):
    try:
        import pyglet.gl.xlib
        pyglet.gl.xlib.glx.glXMakeContextCurrent(self._window.context.x_display, 0, 0, None)
    except:
        pass

I've done a couple of tests and everything works on my side.

@cosw0t
Copy link
Contributor Author

cosw0t commented Jun 17, 2020

That makes a lot of sense. Somehow i thought there should be a platform-dependent version that mirrors glXMakeContextCurrent for wgl, egl, etc.

thanks

see request #124

@awarn314
Copy link

did this ever get resolved? I still get the error "AttributeError: module 'pyglet.gl' has no attribute 'xlib'" when using the example file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants