23

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?

akaRem
  • 7,326
  • 4
  • 29
  • 43
  • 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 Dec 02 '13 at 17:43
  • Chances are you're running into this issue: [PyCharm - $PATH on OS X](http://stackoverflow.com/questions/8732119/pycharm-path-on-os-x) – Lukas Graf Dec 02 '13 at 17:49
  • @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 Dec 02 '13 at 18:04
  • 1
    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](http://stackoverflow.com/a/14961166/1599111), and you should be fine. – Lukas Graf Dec 02 '13 at 18:09
  • @LukasGraf yes, thats it, but solution was not clear, and it was hard to fix my problem. Now everything works. Thank you very much! – akaRem Dec 02 '13 at 18:33
  • I would have suggested to mark your question as a duplicate and upvote the other guy's answer, but I see you already posted an answer of your own. – Lukas Graf Dec 02 '13 at 18:34
  • @LukasGraf How do you think, shall I duplicate my answer on that question? – akaRem Dec 02 '13 at 18:36
  • I would much rather edit `Kentzo`'s answer and add in the details from your answer. Doesn't get you any reputation, but it'll be better for anyone that finds that question. – Lukas Graf Dec 02 '13 at 18:40
  • 3
    @LukasGraf Thank you for mentioning graphviz. Boy, I had trouble figuring out where `dot` comes from – Antony Dec 09 '13 at 04:57
  • Note: the mentioned fix only addresses 1 dir, not the root problem. If you have other things on your path that you need, like pyenv, other local binary dirs, etc., you should fix the root problem - the $PATH. This problem affects all JetBrains product and affects the builtin terminal and run/debug cmds. I have a fix for zsh on *nix/mac here (https://stackoverflow.com/questions/51006002) with enough detail that you should be able to duplicate the solution in bash or whatever shell you use. – Steve Tarver Jun 25 '18 at 16:27

4 Answers4

33

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

gogasca
  • 9,283
  • 6
  • 80
  • 125
10

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

akaRem
  • 7,326
  • 4
  • 29
  • 43
  • 1
    Actually, value should be `/usr/local/bin:$PATH` - otherwise you drop the contents of your default `$PATH` (unless PyCharm appends to it by default). – Lukas Graf Dec 02 '13 at 18:33
  • @LukasGraf To be honest, I don't really understand, what exactly I did, but it works. :( How to check, did I drop contents of $PATH? – akaRem Dec 02 '13 at 18:40
  • @LukasGraf `/usr/local/bin:$PATH` works too. I suppose, that this is more correct value, so I've updated my answer. – akaRem Dec 02 '13 at 18:44
  • To check: Print the contents of `os.env['PATH']` *before* and *after* you modify your PyCharm configuration. Everything that was in there before should still be in there afterwards. – Lukas Graf Dec 02 '13 at 18:48
  • 3
    @LukasGraf before +$PATH: `/usr/local/bin:/Users/user/Projects/py27/bin` after +$PATH: `/usr/local/bin:$PATH:/Users/user/Projects/py27/bin` -> I think $PATH needs to be removed. – akaRem Dec 02 '13 at 18:54
0

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.

jucor
  • 21
  • 5
0

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\

Kris Kizlyk
  • 151
  • 8