Using pycallgraph failed in python3.7 conda virtual envirenment

196 Views Asked by At

I want to use pycallgraph tool to track the functions call, but errors occur as below:

Traceback (most recent call last):
  File "example.py", line 15, in <module>
    graphviz = GraphvizOutput()
  File "/home/russell/anaconda3/envs/tvm-build/lib/python3.7/site-packages/pycallgraph/output/graphviz.py", line 24, in __init__
    Output.__init__(self, **kwargs)
  File "/home/russell/anaconda3/envs/tvm-build/lib/python3.7/site-packages/pycallgraph/output/output.py", line 19, in __init__
    [setattr(self, k, v) for k, v in kwargs.iteritems()]
AttributeError: 'dict' object has no attribute 'iteritems'

The code is:

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


graphviz = GraphvizOutput() ##error occurs
graphviz.output_file = 'regexp.png'
config = Config(include_stdlib=True)

The envirenments: python:3.7.16 pycallgraph:1.0.1 graphviz: enter image description here

I want to make this execute successfully and get the functions call relationship pic.

2

There are 2 best solutions below

0
On

In Python 3, this method has been removed. items() is equivalent. [setattr(self, k, v) for k, v in kwargs.items()]

1
On

https://pypi.org/project/pycallgraph/ The last version 1.0.1 was released in 2013. The code is obviously for Python2. The homepage doesn't work.

The bottom line: the project is old, outdated, abandoned, only works with Python 2.7.