Closed scarf005 closed 2 years ago
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: https://github.com/joowani/binarytree/blob/397e65fa08f463f23983e67ac8db406b8e6671be/binarytree/__init__.py#L512
Digraph._repr_svg_()
and is solved by replacing the line with:
return self.graphviz()._repr_image_svg_xml()
(_repr_image_svg_xml() returns str)
_repr_image_svg_xml()
str
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:
ubuntu 21.10 python 3.10.1 ipython 8.1.1 binarytree 6.5.1 graphviz 0.20
21.10
3.10.1
8.1.1
6.5.1
0.20
thank you for the PR @scarf005! Sorry it took so long to merge.
Summary
while trying to repr tree as image following the example provided on readme, got following error:
looks like it's because
Digraph._repr_svg_()
is deprecated: https://github.com/joowani/binarytree/blob/397e65fa08f463f23983e67ac8db406b8e6671be/binarytree/__init__.py#L512and is solved by replacing the line with:
(
_repr_image_svg_xml()
returnsstr
)Log
text:
screenshot:
Versions
ubuntu
21.10
python3.10.1
ipython8.1.1
binarytree6.5.1
graphviz0.20