Skip to content

graphviz's _repr_svg_() deprecation causes error on jupyter notebook #40

@scarf005

Description

@scarf005

Summary

while trying to repr tree as image following the example provided on readme, got following error:

AttributeError: 'Digraph' object has no attribute '_repr_svg_'

looks like it's because Digraph._repr_svg_() is deprecated:

return str(self.graphviz()._repr_svg_())

and is solved by replacing the line with:

return self.graphviz()._repr_image_svg_xml()

(_repr_image_svg_xml() returns str)

Log

text:

from binarytree import tree
t = tree()
t
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
File ~/.asdf/installs/python/3.10.1/lib/python3.10/site-packages/IPython/core/formatters.py:343, in BaseFormatter.__call__(self, obj)
    [341](file:///home/scarf/.asdf/installs/python/3.10.1/lib/python3.10/site-packages/IPython/core/formatters.py?line=340)     method = get_real_method(obj, self.print_method)
    [342](file:///home/scarf/.asdf/installs/python/3.10.1/lib/python3.10/site-packages/IPython/core/formatters.py?line=341)     if method is not None:
--> [343](file:///home/scarf/.asdf/installs/python/3.10.1/lib/python3.10/site-packages/IPython/core/formatters.py?line=342)         return method()
    [344](file:///home/scarf/.asdf/installs/python/3.10.1/lib/python3.10/site-packages/IPython/core/formatters.py?line=343)     return None
    [345](file:///home/scarf/.asdf/installs/python/3.10.1/lib/python3.10/site-packages/IPython/core/formatters.py?line=344) else:

File ~/.asdf/installs/python/3.10.1/lib/python3.10/site-packages/binarytree/__init__.py:512, in Node._repr_svg_(self)
    [506](file:///home/scarf/.asdf/installs/python/3.10.1/lib/python3.10/site-packages/binarytree/__init__.py?line=505) """Display the binary tree using Graphviz (used for `Jupyter notebooks`_).
    [507](file:///home/scarf/.asdf/installs/python/3.10.1/lib/python3.10/site-packages/binarytree/__init__.py?line=506) 
    [508](file:///home/scarf/.asdf/installs/python/3.10.1/lib/python3.10/site-packages/binarytree/__init__.py?line=507) .. _Jupyter notebooks: https://jupyter.org
    [509](file:///home/scarf/.asdf/installs/python/3.10.1/lib/python3.10/site-packages/binarytree/__init__.py?line=508) """
    [510](file:///home/scarf/.asdf/installs/python/3.10.1/lib/python3.10/site-packages/binarytree/__init__.py?line=509) try:
    [511](file:///home/scarf/.asdf/installs/python/3.10.1/lib/python3.10/site-packages/binarytree/__init__.py?line=510)     # noinspection PyProtectedMember
--> [512](file:///home/scarf/.asdf/installs/python/3.10.1/lib/python3.10/site-packages/binarytree/__init__.py?line=511)     return str(self.graphviz()._repr_svg_())
    [514](file:///home/scarf/.asdf/installs/python/3.10.1/lib/python3.10/site-packages/binarytree/__init__.py?line=513) except (SubprocessError, ExecutableNotFound, FileNotFoundError):
    [515](file:///home/scarf/.asdf/installs/python/3.10.1/lib/python3.10/site-packages/binarytree/__init__.py?line=514)     return self.svg()

AttributeError: 'Digraph' object has no attribute '_repr_svg_'
Node(3)

screenshot:
image

Versions

ubuntu 21.10
python 3.10.1
ipython 8.1.1
binarytree 6.5.1
graphviz 0.20

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions