pythonocc-core报错:SetPixelFormat failed. Error code: 2000 raised from method Init of class Display3d

错误内容

使用Pythonocc-core运行时,出现以下报错

 ###### 3D rendering pipe initialisation #####
Display3d class initialization starting ...
Aspect_DisplayConnection created.
Graphic_Driver created.
V3d_Viewer created.
AIS_InteractiveContext created.
V3d_View created
WNT window created.
Traceback (most recent call last):
  File "E:/Project/camera_calibration_tool/pingzi.py", line 41, in <module>
    display, start_display, add_menu, add_function_to_menu = init_display()
  File "F:\Anaconda\envs\CAL\lib\site-packages\OCC\Display\SimpleGui.py", line 192, in init_display
    win.canva.InitDriver()
  File "F:\Anaconda\envs\CAL\lib\site-packages\OCC\Display\qtDisplay.py", line 123, in InitDriver
    self._display.Create(window_handle=self.GetHandle(), parent=self)
  File "F:\Anaconda\envs\CAL\lib\site-packages\OCC\Display\OCCViewer.py", line 181, in Create
    self.Init(self._window_handle)
  File "F:\Anaconda\envs\CAL\lib\site-packages\OCC\Core\Visualization.py", line 171, in Init
    return _Visualization.Display3d_Init(self, handle)
RuntimeError: Aspect_GraphicDeviceDefinitionErrorOpenGl_Window::CreateWindow: SetPixelFormat failed. Error code: 2000 raised from method Init of class Display3d

解决方法

打开运行环境文件F:\anaconda3\envs\pyocc\lib\site-packages\OCC\Display\qtDisplay.py
将38行内容从:

class qtBaseViewer(QtOpenGL.QGLWidget):

替换成

class qtBaseViewer(QtWidgets.QWidget):

结语

替换后成功运行√
最后附上官方git连接:pythonocc-core

你可能感兴趣的:(python)