Monday, March 30, 2015

Solving the problems with pycallgraph under Windows

I've installed Python Call Graph (pycallgraph) using pip:

pip install pycallgraph

Then I've tried to run it:

pycallgraph graphviz -- ./

But I've got a message:
"pycallgraph" is not recognized as an internal or external command, operable program or batch file.

Ok, then I found pycallgraph location and executed it:

python c:\Python27\Scripts\pycallgraph graphviz -- ./

But alas, I've got error message:

E:\>python c:\Python27\Scripts\pycallgraph graphviz -- ./
Traceback (most recent call last):
  File "c:\Python27\Scripts\pycallgraph", line 25, in
    with __pycallgraph.PyCallGraph(config=__config):
  File "C:\Python27\lib\site-packages\pycallgraph\", line 32, in __init__
  File "C:\Python27\lib\site-packages\pycallgraph\", line 53, in reset
  File "C:\Python27\lib\site-packages\pycallgraph\", line 97, in prepare_output
  File "C:\Python27\lib\site-packages\pycallgraph\output\", line 63, in sanity_check
  File "C:\Python27\lib\site-packages\pycallgraph\output\", line 96, in ensure_binary
    'The command "{}" is required to be in your path.'.format(cmd))
pycallgraph.exceptions.PyCallGraphException: The command "dot" is required to be in your path.

I've installed graphviz:

pip install graphviz

But the problem remained.

Then I've downloaded current stable release of graphviz (graphviz-2.38.msi) from official site:

And installed it.
You can check that graphviz for python is trying to execute dot.exe tool (subprocess.Popen(cmd) in graphviz\, so to solve the problem you can go to the graphviz directory and call pycallgraph:
cd c:\Program Files (x86)\Graphviz2.38\bin
c:\Program Files (x86)\Graphviz2.38\bin>python c:\Python27\Scripts\pycallgraph graphviz -o main.png -- e:\

After that you'll get main.png image inside C:\Program Files (x86)\Graphviz2.38\bin\ directory.

PS. You can add graphviz directory to PATH environment variable.


  1. I get this error. Can you please help to fix it:
    can't find '__main__' module in 'C:\\Users\\Ragesh\\appdata\\local\\programs\\python\\python37\\lib\\site-packages\\pycallgraph'

    1. Hi!
      Seems like you are trying to pass a directory `pycallgraph` to your Python interpreter.
      Try to run in this directory.

    2. Look one dir down, i.e. inside pycallgraph dir theres a file named