5

I use line_profiler in my .ipynb file with vscode:

from line_profiler import LineProfiler
lpf = LineProfiler()
lpf.add_function(train_loop)
lpf.add_function(Covid_dataset.__getitem__)
lpf.add_function(Covid_dataset.__len__)
lpf.enable_by_count()
lpf.runcall(train_loop, model, train_dataloader, optimizer, criterion)
lpf.print_stats()

it used to work correctly,but today i meet this:

Timer unit: 1e-07 s

Total time: 1.33e-05 s

Could not find file C:\Users\12978\AppData\Local\Temp\ipykernel_11908\222113089.py
Are you sure you are running this program from the same directory
that you ran the profiler from?
Continuing without the function's contents.

The only change is that I debug my code in notebook now. And if i run this cell in debug mode, it works again.

It seem to be like jupyter runs the cell in different path when debugging, but the line_profiler now can only get the debug path, but cannot get the normal one.

How to fix it ?

Fadelis Hu
  • 59
  • 3
  • I used to have no output. Now I use it in debug mode and finally can see the results. Thanks – mustafa candan Mar 06 '22 at 15:37
  • Could you fix it? I am having the same problem. Everything except the LIne Contents is displayed which is pretty useless! It used to work perfectly for me even in Jupyter Notebook a few months ago but now it isn't, both in Notebook as well as in Lab. – knowledge_seeker Jun 22 '22 at 22:11
  • I'm having the same problem. I do `%load_ext line_profiler` in VScode and then `%lprun -f test test(1)`. I see all the hits and time but not the actual line of code. Did you manage to solve it? – Marc de la Barrera i Bardalet Oct 21 '22 at 16:34

0 Answers0