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

output is graphviz.files.Source object #47

Closed
sinancetinkaya opened this issue Dec 27, 2019 · 7 comments
Closed

output is graphviz.files.Source object #47

sinancetinkaya opened this issue Dec 27, 2019 · 7 comments

Comments

@sinancetinkaya
Copy link

In the document it says

>>> x = []
>>> y = [x, [x], dict(x=x)]
>>> import objgraph
>>> objgraph.show_refs([y], filename='sample-graph.png')
Graph written to ....dot (... nodes)
Image generated as sample-graph.png

But I get this instead, there is no image file

Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 22:20:52) [MSC v.1916 32 bit (Intel)]
Type 'copyright', 'credits' or 'license' for more information
IPython 7.10.2 -- An enhanced Interactive Python. Type '?' for help.
PyDev console: using IPython 7.10.2
Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 22:20:52) [MSC v.1916 32 bit (Intel)] on win32
x = []
y = [x, [x], dict(x=x)]
import objgraph
objgraph.show_refs([y], filename='sample-graph.png')
Out[5]: <graphviz.files.Source at 0x58aa170>

graphviz is installed

pip3 install graphviz
Requirement already satisfied: graphviz in d:\program files\python\python37-32\lib\site-packages (0.13.2)
@mgedmin
Copy link
Owner

mgedmin commented Dec 30, 2019

Ah yes, this is the feature where if you used a graphical ipython/jupyter console, you'd see the graph inline: #28

Clearly it doesn't work that well in a text-only console.

Two things seem broken to me:

  • the detection of ipython's interactive console is supposed to check if this is a terminal-only console and do nothing special in that case.
  • an explicit filename=... argument should override this, but it doesn't (and I see where the bug is!)

Regarding the first, could you please report what the following returns in your ipython shell?

get_ipython().__class__.__name__

Regarding the second, I've just committed a fix. Can you please try git master?

@sinancetinkaya
Copy link
Author

the first:
image

the second:

>>> y = [x, [x], dict(x=x)]
>>> import objgraph
>>> objgraph.show_refs([y], filename='sample-graph.png')
Graph written to D:\Temp\objgraph-hu58dy85.dot (4 nodes)
Image renderer (dot) not found, not doing anything else

@mgedmin
Copy link
Owner

mgedmin commented Dec 30, 2019

Oh, you are using Jupyter!

Maybe the inline graphs don't work in the web-based console? I think the original contributor was using qtconsole.

Or maybe the problem is just that you don't have graphviz itself installed:

Image renderer (dot) not found, not doing anything else

@sinancetinkaya
Copy link
Author

sinancetinkaya commented Dec 30, 2019

Yes, I tested get_ipython().__class__.__name__ in jupyter.
But updated objgraph was tested in python console of pycharm
See the first post graphviz is installed.

@mgedmin
Copy link
Owner

mgedmin commented Dec 30, 2019

Yes, I tested get_ipython().__class__.__name__ in jupyter.
But updated objgraph was tested in python console of pycharm

It would be helpful to also know what get_ipython().__class__.__name__ produces in the pycharm console too. (I'm assuming that's what you copied and pasted the Out[5]: <graphviz.files.Source at 0x58aa170> bit in the original post?)

See the first post graphviz is installed.

You have the graphviz Python library, but not graphviz the actual program that lays out and draws graphs.

Also, the programs installed (specifically dot.exe) need to be on your PATH so that objgraph can find it. I don't recall if graphviz has an installer that can take care of this, or if you need to update your PATH manually from the control panel.

@sinancetinkaya
Copy link
Author

I didn't know this would require this much work... I no longer need it but here it is:

It would be helpful to also know what get_ipython().__class__.__name__ produces in the pycharm console too.

get_ipython().__class__.__name__
Out[6]: 'PyDevTerminalInteractiveShell'

You have the graphviz Python library, but not graphviz the actual program that lays out and draws graphs.

Also, the programs installed (specifically dot.exe) need to be on your PATH so that objgraph can find it. I don't recall if graphviz has an installer that can take care of this, or if you need to update your PATH manually from the control panel.

I will do that when I need objgraph again.

@mgedmin
Copy link
Owner

mgedmin commented Dec 30, 2019

PyDevTerminalInteractiveShell

Thank you, that'll let me improve the autodetection code to avoid trying to put inline graphics in environments where they don't work!

bmwiedemann referenced this issue in bmwiedemann/openSUSE Jun 11, 2021
https://build.opensuse.org/request/show/896443
by user dirkmueller + dimstar_suse
- version update to 3.5.0
  - Do not require ``mock`` for the test suite on Python 3; use unittest.mock
    instead.
  - 100% test coverage for each version of Python rather than combined, using
    ``coverage-python-version``.
  - Add the optional ``extra_node_attrs`` parameter to ``show_backrefs`` and
    ``show_backrefs``
  - Fix IPython/Jupyter inline graph support code that would kick in even if you
    explicitly passed a filename='foo.png' argument to
    ``show_refs``/``show_backrefs``.  See `issue 47
    <https://github.com/mgedmin/objgraph/issues/47>`_.
  - Add support for Python 3.8.
  - Drop support for Python 3.5.
- %check: use %pytest rpm macro
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants