1

I have tried what has been suggested. On the simplest of code, I get the familiar error that others have mentioned. The error is:

@profile
NameError: name 'profile' is not defined

on the minimal code:

@profile
def hello():
  print('Testing')

hello()

from the command line:

kernprof -l hello.py

I have imported future and I have even installed from the distribution outside of my virtualenv. This was a previous suggestion, as was importing future module.

So

import future
import cProfile

@profile
def hello():
  print('Testing')

hello()

also gives the same error. I cannot get this line profiler to work with pip or even from the raw repository. My versions are:

pip 8.1.2
python 2.7
disruptive
  • 5,687
  • 15
  • 71
  • 135

2 Answers2

1

I fixed this my cloning the code from https://github.com/rkern/line_profiler and rebuilding and then calling the kernprof from the binary install location.

disruptive
  • 5,687
  • 15
  • 71
  • 135
-1

You can add the following snippet at the beginning of your python file:

import line_profiler
profile = line_profiler.LineProfiler()
VSZM
  • 1,341
  • 2
  • 17
  • 31