使用jupyter笔记本时line_profiler找不到当前文件

Fad*_* Hu 5 python line-profiler visual-studio-code jupyter-notebook

我在 .ipynb 文件中使用 vscode 的 line_profiler:

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()
Run Code Online (Sandbox Code Playgroud)

它曾经工作正常,但今天我遇到了这个:

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.

Run Code Online (Sandbox Code Playgroud)

唯一的变化是我现在在笔记本中调试我的代码。如果我在调试模式下运行这个单元,它会再次工作。

看起来好像jupyter在调试时在不同的路径中运行单元,但是line_profiler现在只能获取调试路径,而无法获取正常路径。

如何修复它?