21
votes

I'm using mac os x and trying to setup pycallgraph.
Ive installed pycallgraph with pip and graphviz with homebrew.
Everything works from shell. But not from pycharm.

from pycallgraph import PyCallGraph
from pycallgraph import Config
from pycallgraph import GlobbingFilter
from pycallgraph.output import GraphvizOutput


config = Config()
config.trace_filter = GlobbingFilter(exclude=[
     'pycallgraph.*',
])

graphviz = GraphvizOutput(output_file='filter_exclude.png')

with PyCallGraph(output=graphviz, config=config):
    def my_fun(): 
        print "HELLO"
    my_fun()

/Users/user/Projects/py27/bin/python /Users/user/Projects/py27_django/test2.py
Traceback (most recent call last):
  File "/Users/user/Projects/py27_django/test2.py", line 15, in <module>
    with PyCallGraph(output=graphviz, config=config):
  File "/Users/user/Projects/py27/lib/python2.7/site-packages/pycallgraph/pycallgraph.py", line 32, in __init__
    self.reset()
  File "/Users/user/Projects/py27/lib/python2.7/site-packages/pycallgraph/pycallgraph.py", line 53, in reset
    self.prepare_output(output)
  File "/Users/user/Projects/py27/lib/python2.7/site-packages/pycallgraph/pycallgraph.py", line 97, in prepare_output
    output.sanity_check()
  File "/Users/user/Projects/py27/lib/python2.7/site-packages/pycallgraph/output/graphviz.py", line 63, in sanity_check
    self.ensure_binary(self.tool)
  File "/Users/user/Projects/py27/lib/python2.7/site-packages/pycallgraph/output/output.py", 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.

Process finished with exit code 1

Here:
/Users/user/Projects/py27/ -> virtualenv dir
/Users/user/Projects/py27_django/ -> project dir


What does it want from me?

4
It wants the dot command (from graphviz) to be in your path. If you start a terminal and do which dot, does it find the dot binary you installed with homebrew?Lukas Graf
Chances are you're running into this issue: PyCharm - $PATH on OS XLukas Graf
@LukasGraf yes, of course: it is /usr/local/bin/dot. Everything works fine from shell, as I said. It is clear, that I must add this path somewhere, but where??akaRem
See the question I linked and the answers to it: homebrew links packages to /usr/local/bin, which isn't in the default $PATH. Your .bash_profile probably adds it to $PATH, but that only applies to terminals. Append /usr/local/bin/ to your $PATH in your PyCharm configuration as described in this answer, and you should be fine.Lukas Graf
@LukasGraf Thank you for mentioning graphviz. Boy, I had trouble figuring out where dot comes fromAntony

4 Answers

28
votes

Install graphviz in MacOS by using:

brew install graphviz

or in Ubuntu by using:

sudo apt-get install graphviz

Then you can test dot by using:

dot -v

You can also download pkg from here

9
votes

The answer is:

In menubar:
Pycharm -> Run -> Edit Configurations...

In dialog:
for selected .py file or for Defaults/Python:

Environment field group:

Environment variables > ... -> + ->
Add entry:
Name: PATH
Value: /usr/local/bin

Include print environment variables should be selected

0
votes

FWIW, this is a behaviour which two other users have filed as an Issue in PyCharm's bugtracker: https://youtrack.jetbrains.com/issue/PY-17816

I'll update this post if the developers comment there.

[Update] On September 22nd 2016, Pycharm developers offered a fix in the Early Access version. https://blog.jetbrains.com/pycharm/2016/09/pycharm-2016-3-eap-is-available-with-initial-support-for-python-3-6/, but this does not seem to have fixed the problem yet.

0
votes

This process worked for my environment; I got the same "dot" error after I compiled. Unfortunately, I was looking for a visual representation of the code which shows inheritance, function calls, more like a flow chart. On the UP-and-UP, I Understand what a profiler does this one worked great!

  • Pycharm: 2020.3.3
  • Python 3.8
  • PyCallGraph3
  • Venv Environment in Pycharm

For it to work in PyCharm on Windows 10:

  1. Install the package under your interpreter: pycallgraph3 File > Settings > Project > Python Interpreter

  2. Install the program called GraphViz (https://graphviz.org/)

  3. Under your Run/Debug Configurations go to Environment Variables:

  4. Paste the following line at the end of the massive list

    ;C:\Program Files\Graphviz\bin;

After here, I didn't test its validity but did it anyway if it didn't work try adding it to your windows path.

  1. In Windows under: System Properties > Environment Variables

  2. FOR USER WINDOW (TOP) Edit > PATH > NEW> add Entry: C:\Program Files\Graphviz\bin\

  3. FOR SYSTEM VARIABLES WINDOW (BOTTOM): Edit > PATH > NEW > add a New Entry: C:\Program Files\Graphviz\bin\