pycallgraph with pycharm does not work

2019-01-13 21:53发布

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?

3条回答
小情绪 Triste *
2楼-- · 2019-01-13 22:42

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

查看更多
淡お忘
3楼-- · 2019-01-13 22:43

Install graphviz in MacOS by using:

brew install graphviz

Then you can test dot by using:

dot -v

You can also download pkg from here

查看更多
何必那么认真
4楼-- · 2019-01-13 22:55

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.

查看更多
登录 后发表回答