无法使用 OpenGL >= 3+ 上下文初始化 Pyglet 窗口

无法使用 OpenGL >= 3+ 上下文初始化 Pyglet 窗口

我通过 ssh 连接到没有监视器的远程服务器,并在尝试运行脚本时收到错误。

ValueError: Failed to initialize Pyglet window with an OpenGL >= 3+ context. If you're logged in via SSH, ensure that you're running your script with vglrun (i.e. VirtualGL). The internal error message was ""

以下是完整的错误消息。

(/home_nfs/haziq/cenvs/hpe) haziq@blender:~/I2L-MeshNet_RELEASE/demo$ python demo.py --gpu 0 --stage param --test_epoch 8                  >>> Using GPU: 0
Load checkpoint from ./snapshot_8.pth.tar
Traceback (most recent call last):
  File "/home_nfs/haziq/cenvs/hpe/lib/python3.7/site-packages/pyrender/platforms/pyglet_platform.py", line 39, in init_context
    width=1, height=1)
  File "/home_nfs/haziq/cenvs/hpe/lib/python3.7/site-packages/pyglet/window/xlib/__init__.py", line 173, in __init__
    super(XlibWindow, self).__init__(*args, **kwargs)
  File "/home_nfs/haziq/cenvs/hpe/lib/python3.7/site-packages/pyglet/window/__init__.py", line 603, in __init__
    config = screen.get_best_config(config)
  File "/home_nfs/haziq/cenvs/hpe/lib/python3.7/site-packages/pyglet/canvas/base.py", line 194, in get_best_config
    raise window.NoSuchConfigException()
pyglet.window.NoSuchConfigException

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "demo.py", line 133, in <module>
    rendered_img = render_mesh(vis_img, mesh_lixel_cam, face, {'focal': focal, 'princpt': princpt})
  File "/home_nfs/haziq/I2L-MeshNet_RELEASE/main/../common/utils/vis.py", line 136, in render_mesh
    renderer = pyrender.OffscreenRenderer(viewport_width=img.shape[1], viewport_height=img.shape[0], point_size=1.0)
  File "/home_nfs/haziq/cenvs/hpe/lib/python3.7/site-packages/pyrender/offscreen.py", line 31, in __init__
    self._create()
  File "/home_nfs/haziq/cenvs/hpe/lib/python3.7/site-packages/pyrender/offscreen.py", line 149, in _create
    self._platform.init_context()
  File "/home_nfs/haziq/cenvs/hpe/lib/python3.7/site-packages/pyrender/platforms/pyglet_platform.py", line 45, in init_context
    'internal error message was "{}"'.format(e)
ValueError: Failed to initialize Pyglet window with an OpenGL >= 3+ context. If you're logged in via SSH, ensure that you're running your script with vglrun (i.e. VirtualGL). The internal error message was ""

如何使用 vglrun 运行我的脚本?我尝试在 Google 上搜索 vglrun,但没有找到答案。

答案1

找到了解决方案 https://github.com/nkolot/SPIN/issues/41

添加此行

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

相关内容