tpaviot / pythonocc-demos

Examples and demos for the pythonocc CAD package
216 stars 115 forks source link

The problem with create Viewer3d on Ubuntu 20.04 LTS VM Google Cloud Platform #45

Closed RobotcomFA closed 3 years ago

RobotcomFA commented 3 years ago

I am working with python 3.8.5 and pythonocc-core 7.5.1 on Ubuntu VM, Google Cloud Platform and I am trying covert shape to png by offscreen_rendering

The error when I am trying create the renderer: offscreen_renderer = Viewer3d()

Exception Type:     RuntimeError
Exception Value:    Aspect_DisplayConnectionDefinitionErrorCan not connect to the server "" raised from method Display3d of class Display3d

Exception Location:     /home/username/miniconda3/lib/python3.8/site-packages/OCC/Core/Visualization.py, line 166, in __init__
Python Executable:  /home/username/miniconda3/bin/python
Python Version:     3.8.5

/home/username/miniconda3/lib/python3.8/site-packages/OCC/Display/OCCViewer.py, line 120, in __init__
Display3d.__init__(self)

/home/username/miniconda3/lib/python3.8/site-packages/OCC/Core/Visualization.py, line 166, in __init__
_Visualization.Display3d_swiginit(self, _Visualization.new_Display3d())

Thank you for your help!

RobotcomFA commented 3 years ago

I finally solved the problem. I use PyVirtualDisplay (a Python wrapper for Xvfb).

from pyvirtualdisplay import Display
from selenium import webdriver

display = Display(visible=0, size=(800, 600))
display.start()

# launch stuff inside virtual display here

display.stop()

https://stackoverflow.com/a/6300672/15518966