"ImportError: No module named pstats" error on Ubuntu
Even though the pstats module (used by cProfile) is part of the Python Standard Library, Ubuntu requires installing a separate package because of its non-free license. For more information, see this Ubuntu bug report. (thanks Luke)
Running this on Ubuntu Karmic:
import cProfile
def my_super_slow_routine(): pass
cProfile.run('my_super_slow_routine()')
Produces this error:
Traceback (most recent call last): File "test_pstats_error.py", line 3, incProfile.run('my_super_slow_routine()') File "/usr/lib/python2.6/cProfile.py", line 36, in run result = prof.print_stats(sort) File "/usr/lib/python2.6/cProfile.py", line 80, in print_stats import pstats ImportError: No module named pstats
Solution:
sudo apt-get install python-profiler
Note: the multiverse repository must be enabled via either update-manager > "Settings..." > "Ubuntu Software" or directly editing /etc/apt/sources.list. (thanks Luke)
2
Comments
—
Comments feed for this post
Post a comment
About
I'm Eliot and this is my notepad for programming topics such as Python, Django, Ubuntu, Emacs, etc... more »
Search Blog
Tags
-
algorithms
(4)
-
aws
(8)
-
blogproject
(20)
-
c_cplusplus
(12)
-
cardstore
(8)
-
colinux
(2)
-
concurrency
(9)
-
conkeror
(2)
-
cygwin
(18)
-
datastructures
(15)
-
datetime
(3)
-
dell
(3)
-
django
(39)
-
emacs
(20)
-
files_directories
(10)
-
install_setup
(7)
-
javascript
(3)
-
keyboard
(6)
-
matplotlib
(5)
-
mercurial
(4)
-
nginx
(2)
-
preferences
(8)
-
processes
(3)
-
pyqt
(18)
-
python
(122)
-
ratpoison
(3)
-
regexes
(5)
-
rsync
(3)
-
softwaretools
(17)
-
sql
(13)
-
ssh
(7)
-
subversion
(6)
-
twisted
(6)
-
ubuntu
(60)
-
urxvt
(5)
-
vxworks
(25)
-
webservices
(4)
-
wmii
(7)
Blogroll
- Adam Gomaa
- Alex Clemesha
- Amir Salihefendic
- Armin Ronacher
- David Beazley
- David Ziegler
- Duncan McGreggor
- Gareth Rushgrave
- Glyph Lefkowitz
- Guido van Rossum
- Ian Bicking
- Jacob Kaplan-Moss
- James Bennett
- James Tauber
- Jesper Noehr
- Matt Harrison
- Nikolay Kolev
- Parand Darugar
- Peter Baumgartner
- Peter Bengtsson
- Rob Hudson
- Simon Willison
- Will McGugan
#1 Luke commented on 2010-01-21:
If you're running on stock installs of some of the newer versions of Ubuntu (for example, I'm on 9), you won't be able to just install python-profiler, because it's not in the apt repositories that are enabled by default (this is apparently due to a licensing issue: https://bugs.launchpad.net/ubuntu/+source/python-defaults/+bug/123755) - in order to get it installed, I had to enable the multiverse repositories for my Ubuntu install.