mgedmin/objgraph

Issue with using objgraph in jupyter console

astrofrog opened this issue · 8 comments

If I use objgraph in an IPython session things work as expected:

In [1]: import objgraph

In [2]: a = 1

In [3]: objgraph.show_backrefs(objgraph.by_type('int'))
Graph written to /var/folders/zy/t1l3sx310d3d6p0kyxqzlrnr0000gr/T/objgraph-5iuhcjwd.dot (0 nodes)
Graph viewer (xdot) not found, generating a png instead
Image generated as /var/folders/zy/t1l3sx310d3d6p0kyxqzlrnr0000gr/T/objgraph-5iuhcjwd.png

However if I use jupyter qtconsole there is no output from show_backrefs, and if I try and specify an output filename, nothing happens:

In [1]: import objgraph

In [2]: a = 1

In [3]: objgraph.show_backrefs(objgraph.by_type('int'))

what could be going on?

objgraph contains code to detect when it's running in Jupyter and display the graph inline in the Jupyter console. This is very likely a bug in that code!

See #23 (comment) and #28 for more details.

Question: do you have https://pypi.python.org/pypi/graphviz installed?

@mgedmin - in some cases I do see a graph inline in Jupyter but I still want to have the ability to export the plot to a file (which it doesn't seem to let me do). In the case above the graph is empty which is why I see nothing in the second case. So the inline drawing does work, it's more that it seems to then not allow exporting to files even if asked explicitly. I'll check later today if I had the PyPI graphviz package installed

You should be able to export to a file, if you explicitly specify filename='foo.png' etc. If that doesn't work as well, that could be another bug.

I'm unable to reproduce the problem using Jupyter QtConsole 4.2.1 on Python 3.6.3/IPython 5.1.0:

ekrano nuotrauka is 2017-10-30 16-31-16

You should be able to export to a file, if you explicitly specify filename='foo.png' etc. If that doesn't work as well, that could be another bug.

This is what I was trying and it didn't work either. I'll post specific version information when I'm back at a computer.

You should be able to export to a file, if you explicitly specify filename='foo.png' etc. If that doesn't work as well, that could be another bug.

This is what I was trying and it didn't work either. I'll post specific version information when I'm back at a computer.

That part was broken but is now fixed in a729c40.

I don't know if this issue which happens in environments created in conda falls under the jurisdiction of this issue. The environment in question is Python 3.7.9 <build - h60c2a47_0> made by conda. I installed Graphviz 2.38 <build - hfd603c8_2> from conda, Objgraph 3.5.0, python-graphviz 0.14.2 and xdot 1.1 from pip. To test the setup out, I ran the basic code given in the documentation (yes, the very first one). The xdot package was not detected I guess.
An example. Look at the python console at the bottom left.
p.s. - I'm sorry for necroposting.

@rediffp is the dot tool on your $PATH? If yes, please file another bug because the detection in objgraph is broken. If not, that's your problem and it's not really a bug -- how is objgraph supposed to find a binary executable installed somewhere, when it's not on the PATH?