如何解决“导入错误:无法加载EGL库',22,找不到指定的模块”

问题描述 投票:1回答:1

[下午好,我想使用pyrender模块从python中的3D模型生成渲染图像。因此,我使用了此Code

# Render offscreen -- make sure to set the PyOpenGL platform
import os
os.environ["PYOPENGL_PLATFORM"] = "egl"
import numpy as np
import trimesh
import pyrender

# Load the FUZE bottle trimesh and put it in a scene
fuze_trimesh = trimesh.load('pyrender/examples/models/fuze.obj')
mesh = pyrender.Mesh.from_trimesh(fuze_trimesh)
scene = pyrender.Scene()
scene.add(mesh)

# Set up the camera -- z-axis away from the scene, x-axis right, y-axis up
camera = pyrender.PerspectiveCamera(yfov=np.pi / 3.0)
s = np.sqrt(2)/2
camera_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],
    ])
scene.add(camera, pose=camera_pose)

# Set up the light -- a single spot light in the same spot as the camera
light = pyrender.SpotLight(color=np.ones(3), intensity=3.0,
                               innerConeAngle=np.pi/16.0)
scene.add(light, pose=camera_pose)

# Render the scene
r = pyrender.OffscreenRenderer(640, 480)
color, depth = r.render(scene)

# Show the images
import matplotlib.pyplot as plt
plt.figure()
plt.subplot(1,2,1)
plt.axis('off')
plt.imshow(color)
plt.subplot(1,2,2)
plt.axis('off')
plt.imshow(depth, cmap=plt.cm.gray_r)
plt.show()

当我运行此代码来生成图像时。我收到此错误:

--------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
C:\Anaconda3\lib\site-packages\OpenGL\platform\egl.py in EGL(self)
     69                 'EGL',
---> 70                 mode=ctypes.RTLD_GLOBAL
     71             )

C:\Anaconda3\lib\site-packages\OpenGL\platform\ctypesloader.py in loadLibrary(dllType, name, mode)
     44     try:
---> 45         return dllType( name, mode )
     46     except Exception as err:

C:\Anaconda3\lib\ctypes\__init__.py in __init__(self, name, mode, handle, use_errno, use_last_error)
    347         if handle is None:
--> 348             self._handle = _dlopen(self._name, mode)
    349         else:

OSError: [WinError 126] Le module spécifié est introuvable

During handling of the above exception, another exception occurred:

ImportError                               Traceback (most recent call last)
<ipython-input-1-e86166a3612b> in <module>()
      4 import numpy as np
      5 import trimesh
----> 6 import pyrender
      7 
      8 # Load the FUZE bottle trimesh and put it in a scene

C:\Anaconda3\lib\site-packages\pyrender\__init__.py in <module>()
      1 from .camera import (Camera, PerspectiveCamera, OrthographicCamera,
      2                      IntrinsicsCamera)
----> 3 from .light import Light, PointLight, DirectionalLight, SpotLight
      4 from .sampler import Sampler
      5 from .texture import Texture

C:\Anaconda3\lib\site-packages\pyrender\light.py in <module>()
      9 
     10 from .utils import format_color_vector
---> 11 from .texture import Texture
     12 from .constants import SHADOW_TEX_SZ
     13 from .camera import OrthographicCamera, PerspectiveCamera

C:\Anaconda3\lib\site-packages\pyrender\texture.py in <module>()
      6 import numpy as np
      7 
----> 8 from OpenGL.GL import *
      9 
     10 from .utils import format_texture_source

C:\Anaconda3\lib\site-packages\OpenGL\GL\__init__.py in <module>()
      1 """OpenGL.GL, the core GL library and extensions to it"""
      2 # early import of our modules to prevent import loops...
----> 3 from OpenGL import error as _error
      4 from OpenGL.GL.VERSION.GL_1_1 import *
      5 from OpenGL.GL.pointers import *

C:\Anaconda3\lib\site-packages\OpenGL\error.py in <module>()
     10 import logging
     11 _log = logging.getLogger( 'OpenGL.error' )
---> 12 from OpenGL import platform, _configflags
     13 from ctypes import ArgumentError
     14 __all__ = (

C:\Anaconda3\lib\site-packages\OpenGL\platform\__init__.py in <module>()
     33     return plugin
     34 
---> 35 _load()
     36 
     37 def types(resultType,*argTypes):

C:\Anaconda3\lib\site-packages\OpenGL\platform\__init__.py in _load()
     30 
     31     # install into the platform module's namespace now
---> 32     plugin.install(globals())
     33     return plugin
     34 

C:\Anaconda3\lib\site-packages\OpenGL\platform\baseplatform.py in install(self, namespace)
     90         """Install this platform instance into the platform module"""
     91         for name in self.EXPORTED_NAMES:
---> 92             namespace[ name ] = getattr(self,name,None)
     93         namespace['PLATFORM'] = self
     94         return self

C:\Anaconda3\lib\site-packages\OpenGL\platform\baseplatform.py in __get__(self, obj, cls)
     12         self.fget = function
     13     def __get__( self, obj, cls ):
---> 14         value = self.fget( obj )
     15         setattr( obj, self.fget.__name__, value)
     16         return value

C:\Anaconda3\lib\site-packages\OpenGL\platform\egl.py in GetCurrentContext(self)
     91     @baseplatform.lazy_property
     92     def GetCurrentContext( self ):
---> 93         return self.EGL.eglGetCurrentContext

C:\Anaconda3\lib\site-packages\OpenGL\platform\baseplatform.py in __get__(self, obj, cls)
     12         self.fget = function
     13     def __get__( self, obj, cls ):
---> 14         value = self.fget( obj )
     15         setattr( obj, self.fget.__name__, value)
     16         return value

C:\Anaconda3\lib\site-packages\OpenGL\platform\egl.py in EGL(self)
     71             )
     72         except OSError as err:
---> 73             raise ImportError("Unable to load EGL library", *err.args)
     74     @baseplatform.lazy_property
     75     def getExtensionProcedure( self ):

ImportError: ('Unable to load EGL library', 22, 'Le module spécifié est introuvable', None, 126, None, 'EGL', None)

我在python中安装了所有必需的模块,例如pyrender模块,但我不知道问题出在哪里。pyrender的工作在这里:link

python exception opengl pyopengl
1个回答
0
投票

您可以尝试

apt-get install libglfw3-dev libgles2-mesa-dev

这解决了我的问题。希望对您有帮助。

© www.soinside.com 2019 - 2024. All rights reserved.