0

I'm working on visualizing a tree and using Graphviz. I'm basing my code on the examples they have in their website, and, I think my code itself is fine. However, I can't run it because of this error. My code is:

from graphviz import Digraph

with open('greetings.json') as json_file:
    data = json.load(json_file)
newstring = data['data']['stitches']['hiImSymmi']['content']
print(newstring)

g = Digraph('G', filename='hello.gv')
g.edge('Hello',newstring[0])
g.view()

The full error message is:

AttributeError                            Traceback (most recent call last)
Input In [7], in <cell line: 2>()
      1 import json
----> 2 from graphviz import Digraph
      3 #from treelib import Node, Tree
      5 with open('greetings.json') as json_file:

File ~/opt/anaconda3/lib/python3.8/site-packages/graphviz/__init__.py:27, in <module>
      1 # graphviz - create dot, save, render, view
      3 """Assemble DOT source code and render it with Graphviz.
      4 
      5 >>> dot = Digraph(comment='The Round Table')
   (...)
     24 }
     25 """
---> 27 from .dot import Graph, Digraph
     28 from .files import Source
     29 from .lang import escape, nohtml

File ~/opt/anaconda3/lib/python3.8/site-packages/graphviz/dot.py:32, in <module>
      3 r"""Assemble DOT source code objects.
      4 
      5 >>> dot = Graph(comment=u'M\xf8nti Pyth\xf8n ik den H\xf8lie Grailen')
   (...)
     28 'test-output/m00se.gv.pdf'
     29 """
     31 from . import backend
---> 32 from . import files
     33 from . import lang
     35 __all__ = ['Graph', 'Digraph']

File ~/opt/anaconda3/lib/python3.8/site-packages/graphviz/files.py:22, in <module>
     16 __all__ = ['File', 'Source']
     19 log = logging.getLogger(__name__)
---> 22 class Base(object):
     24     _engine = 'dot'
     26     _format = 'pdf'

File ~/opt/anaconda3/lib/python3.8/site-packages/graphviz/files.py:28, in Base()
     24 _engine = 'dot'
     26 _format = 'pdf'
---> 28 _encoding = backend.ENCODING
     30 @property
     31 def engine(self):
     32     """The layout commmand used for rendering (``'dot'``, ``'neato'``, ...)."""

AttributeError: module 'graphviz.backend' has no attribute 'ENCODING'

I understand that a similar question about the same kind of error was asked previously. However, I don't really understand the answers that were given to that question. Any help with a specific way to fix this would be greatly appreciated. Thanks a lot.

  • Does this answer your question? https://stackoverflow.com/questions/69989691/how-to-resolve-attributeerror-module-graphviz-backend-has-no-attribute-encod – albert Apr 14 '22 at 10:53
  • Does this answer your question? [how to resolve AttributeError: module 'graphviz.backend' has no attribute 'ENCODING'](https://stackoverflow.com/questions/69989691/how-to-resolve-attributeerror-module-graphviz-backend-has-no-attribute-encod) – joanis Apr 14 '22 at 13:48

0 Answers0