Monday, January 23, 2012

Install cProfile on debian 6.0.3 (squeeze)

So you just seen this when tried to profile something on debian squeeze

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.6/", line 36, in run
    result = prof.print_stats(sort)
  File "/usr/lib/python2.6/", line 80, in print_stats
    import pstats
ImportError: No module named pstats

Well all is need to fix it is to enable a repository and then install python-profile

echo 'deb squeeze main non-free' >> /etc/apt/sources.list
# replace .ca. with your country code
apt-get update
aptitude install  python-profiler

>>> import cProfile
>>> def f():
...     print 'called'
         3 function calls in 0.000 CPU seconds

   Ordered by: standard name

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.000    0.000    0.000    0.000 :1(f)
        1    0.000    0.000    0.000    0.000 :1()
        1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}


Anonymous said...

Hmm. I'm on squeeze but I see:

$ sudo aptitude install python-profiler
"python-profiler" exists in the package database, but it is not a
real package and no package provides it.

$ lsb_release -rc
Release: 6.0.4
Codename: squeeze

Anonymous said...

Nope, right you are. I did the sources change on one machine but was installing on a different one. Everything you say is fine. Ignore me.