Python PyCallGraphException

1.6k Views Asked by At

I have copied an example from their own website but i do not know how to get it working.

Link to their example

This is my code:

from pycallgraph import PyCallGraph
from pycallgraph.output import GraphvizOutput


class Banana:

    def eat(self):
        pass

class Person:

    def __init__(self):
        self.no_bananas()

    def no_bananas(self):
        self.bananas = []

    def add_banana(self, banana):
        self.bananas.append(banana)

    def eat_bananas(self):
        [banana.eat() for banana in self.bananas]
        self.no_bananas()


def main():
    graphviz = GraphvizOutput()
    graphviz.output_file = 'basic.png'

    with PyCallGraph(output=graphviz):
        person = Person()
        for a in xrange(10):
            person.add_banana(Banana())
        person.eat_bananas()

if __name__ == '__main__':
    main()

And this is the error i am receiving when trying to compile it:

  File "test_pycallgraph.py", line 43, in <module>
    main()
  File "test_pycallgraph.py", line 35, in main
    with PyCallGraph(output=graphviz):

    'The command "{}" is required to be in your path.'.format(cmd))
pycallgraph.exceptions.PyCallGraphException: The command "dot" is required to be in your path.
2

There are 2 best solutions below

0
On BEST ANSWER

It seems that the library you want to use makes an internal call to the the dot command. But since dot is not in your PATH, the library cannot find the dot executable and raises an exception.

You most likely need to install dot, which is a command line tool for drawing directed graphs. Make sure you have it installed.

If you already have it installed, make sure you add it’s location to your PATH. See this Stack Overflow answer for more information about modifying your PATH.

0
On

The previous answer was a bit too vague. You need to find dot.exe, which for me was in C:\Program Files (x86)\Graphviz2.38\bin so I went to the following: control panel > system > advanced system settings > Environment Variables... and then in the bottom box for System Variables, find Path, select it and select edit, then select new and paste the path in. Now close and reopen cmd.exe and see simple type in 'dot' and hit enter. If there's no error, the path was setup properly.