mgedmin / objgraph

Visually explore Python object graphs
http://mg.pov.lt/objgraph/
MIT License
753 stars 72 forks source link

Can't get to work on Ipython #23

Open jonathanng opened 8 years ago

jonathanng commented 8 years ago

I'm sorry if this seems like a dumb question, but I'm running Jupyter, Python 2.7, Windows, and Ipython notebook. I have installed graphviz and xdot.

from StringIO import StringIO
import objgraph

x = [[1,2,3], 4,5,6]
objgraph.show_refs([x], output=StringIO())

I don't see anything when I run this.

mgedmin commented 8 years ago

You've asked for the output to be written into a StringIO(). objgraph dutifully writes it there. Since you don't even keep a reference to the StringIO(), you won't ever see the output.

What happens if you use objgraph.show_refs([x]) without specifying output?

jonathanng commented 8 years ago

Thanks for the response. Makes sense. I was trying to figure out the IPython file like type equivalent.

In any case, I ran this:

from StringIO import StringIO
import objgraph

x = [[1,2,3], 4,5,6]
objgraph.show_refs([x])

And I just got this. No graphs.

Graph written to c:\windows\temp\objgraph-u33pp_.dot (8 nodes)
Spawning graph viewer (xdot)
mgedmin commented 8 years ago

So xdot doesn't work on Windows? Strange/sad.

There's probably some way to detect the Jupyter/IPython web console and integrate with it nicely. I wish I knew how. It would be nicer than opening a standalone graph viewer window anyway.

dmitriyshashkin commented 7 years ago

Rather simple way to display graph in jupyter is to use objgraph together with graphviz package:

import objgraph

from StringIO import StringIO
from graphviz import Source

s = StringIO()

objgraph.show_refs([df], output=s)

s.seek(0)
Source(s.read())
mgedmin commented 7 years ago

This is now implemented in git master (thank you @account-login for the PR!). I'd appreciate reports whether it works well enough, and whether the documentation is sufficient.

(E.g. I think you need a 3rd-party package (graphviz) that is not installed by default, and maybe I should mention that in the docs somewhere!)