Python - cProfile not running

I tried to run a performance test of my code using cProfile, but unfortunately, no matter how I tried, cProfile refused to function normally. Here is what I did:

import cProfile
cProfile.run('addNum()')  # addNum() is a very simple function that adds a bunch of 
                          # numbers into a dictionary

and here is what I got:

Traceback (most recent call last):
File "C:\Program Files\Wing IDE 101 4.1\src\debug\tserver\_sandbox.py", line 1, in <module>
# Used internally for debug sandbox under external interpreter
File "C:\Python27\Lib\cProfile.py", line 36, in run
result = prof.print_stats(sort)
File "C:\Python27\Lib\cProfile.py", line 81, in print_stats
pstats.Stats(self).strip_dirs().sort_stats(sort).print_stats()
File "C:\Python27\Lib\pstats.py", line 81, in __init__
self.init(arg)
File "C:\Python27\Lib\pstats.py", line 95, in init
self.load_stats(arg)
File "C:\Python27\Lib\pstats.py", line 124, in load_stats
self.__class__, arg)
TypeError: Cannot create or construct a <class pstats.Stats at 0x01AE9CA8> object from '<cProfile.Profile object at 0x01ACC470>''

Can someone help me debug this and hopefully provide a solution?

I am running Python 2.7.3 on Wing IDE 101 ver4.1.

Thank!!!

+5
source share
1 answer

This seems like a problem with the pStats module, and not with cProfile.

can you try to do

import pstats

If this says pstats cannot be imported, try installing python-profiler again. It comes with python itself, but that might be messed up in your case. IF pstats does not exist.

apt-get linux, , python-profiler.

, !

+3

All Articles