Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't get to work on Ipython #23

Open
jonathanng opened this issue Sep 12, 2015 · 5 comments
Open

Can't get to work on Ipython #23

jonathanng opened this issue Sep 12, 2015 · 5 comments

Comments

@jonathanng
Copy link

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
Copy link
Owner

mgedmin commented Sep 12, 2015

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
Copy link
Author

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
Copy link
Owner

mgedmin commented Sep 13, 2015

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
Copy link

dmitriyshashkin commented Sep 29, 2016

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
Copy link
Owner

mgedmin commented Nov 21, 2016

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!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants