PyWavefront icon indicating copy to clipboard operation
PyWavefront copied to clipboard

cannot visualize inside Google Colab

Open monacv opened this issue 3 years ago • 5 comments

Hello,

Could you please guide me how to interactively or even statically visualize the obj file inside Google Colab?

import pywavefront
from pywavefront import visualization

obj = pywavefront.Wavefront('Data/examples/plane.obj')

visualization.draw(obj)

Error is:


---------------------------------------------------------------------------

NoSuchDisplayException                    Traceback (most recent call last)

<ipython-input-33-fcec2c1ce422> in <module>()
      1 import pywavefront
----> 2 from pywavefront import visualization
      3 
      4 obj = pywavefront.Wavefront('Data/examples/plane.obj')
      5 

7 frames

/usr/local/lib/python3.7/dist-packages/pyglet/canvas/xlib.py in __init__(self, name, x_screen)
    121         self._display = xlib.XOpenDisplay(name)
    122         if not self._display:
--> 123             raise NoSuchDisplayException('Cannot connect to "%s"' % name)
    124 
    125         screen_count = xlib.XScreenCount(self._display)

NoSuchDisplayException: Cannot connect to "None"

Screenshot from 2021-03-18 20-40-55

monacv avatar Mar 19 '21 00:03 monacv

I would interpret that to mean it is looking for an X11 server. Does Google Colab support that?

I did a quick search and turned up this Stackoverflow:

https://stackoverflow.com/questions/60886590/how-to-setup-pyglet-to-work-with-manim-in-colab

Seems Colab may support pyvirtualdisplay. Can you give that a shot?

greenmoss avatar Mar 19 '21 01:03 greenmoss

Hi Kurt,

Thanks a lot for your response. So pyvirtualdisplay didn't work for me following the StackOverflow example also not sure how to connect it with the visualization of piglet

could you please elaborate with a code example? Screenshot from 2021-03-18 21-18-31 Screenshot from 2021-03-18 21-18-25

monacv avatar Mar 19 '21 01:03 monacv

Looks like you need Xvfb (X virtual frame buffer). Is that something you have to manually add in Colab?

I did another search, and in this answer the person is first using apt to install xvfb:

https://stackoverflow.com/questions/50107530/how-to-render-openai-gym-in-google-colab

Can you try that?

greenmoss avatar Mar 19 '21 01:03 greenmoss

Could be easier to use trimesh for this : https://github.com/mikedh/trimesh

It does support inline visualization with tree.js. I have not used Google Colab much but I assume things working in notebook will also work there.

einarf avatar Mar 19 '21 06:03 einarf

@einarf yeah I initially tried that and got this error Screenshot from 2021-03-19 14-28-50

monacv avatar Mar 19 '21 18:03 monacv