rkern / line_profiler

(OLD REPO) Line-by-line profiling for Python - Current repo ->
https://github.com/pyutils/line_profiler
Other
3.6k stars 254 forks source link

NameError: name 'profile' is not defined #53

Closed aphearin closed 7 years ago

aphearin commented 8 years ago

@rkern - I have recently installed line_profiler using pip, with no apparent problems. I attempt to run the exact trivial test in #35 and run into the exact same error message. #35 refers to #25 as the resolution to the problem, but reading through #25 I do not see where the problem was resolved. I use OS X with python 2.7.11

Traceback (most recent call last): File "/Users/aphearin/anaconda/bin/kernprof", line 11, in sys.exit(main()) File "/Users/aphearin/anaconda/lib/python2.7/site-packages/kernprof.py", line 221, in main execfile(script_file, ns, ns) File "hello_world.py", line 2, in @profile NameError: name 'profile' is not defined

Bernhard10 commented 8 years ago

The solution mentioned in #25 seems to be only implemented in the master branch, not in the pip package. Uninstalling the pip version, cloning the git repo and manually running setup.py (requires cython) helps.

Nodd commented 8 years ago

@rkern maybe it's time for another release, since this bug keeps appearing in the issues ?

aphearin commented 8 years ago

Ahh, ok, yes, thanks, I uninstalled, cloned master 19603402e8686407dd19882fd80764d15b2f8499, ran python setup.py install, and then it works as advertised. Thanks @Bernhard10 . I'm now able to use the code, which is great, but I guess I'd like to second @Nodd and suggest considering a new release. Either way, thanks to @rkern for this extremely useful tool.

thomasaarholt commented 8 years ago

Hiya, just thought I'd point out that the pip version still hasn't been updated to reflect #25. Is there a reason for this? I spent a little while trying to figure out what on earth I was doing wrong before realising the fault wasn't with me.

thomasaarholt commented 8 years ago

Actually, I have this problem with master as well. I'm calling it using Jupyter Notebook according to the code below. I've inserted @profile above the appropriate function, and ran kernprof -1 filewithfunction.py

%matplotlib qt4 
%load_ext line_profiler
import hyperspy.api as hs

path = "mypath"
filename = "myfile.test"

%lprun -f hs.load(path+filename)

I've tried installing it via pip install -e ./ and python setup.py install, without any difference.

Any suggestions?

Edit: Having tried #65, I see that master hasn't been updated for iPython 5. I guess that's why I was having trouble. I've tested the branch - which didn't help, until I did: %lprun import hyperspy.api as hs

I think I may simply be using line_profiler a bit wrongly.

caethan commented 7 years ago

New 2.0 release should fix this (reopen if there's still a problem, please).