最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

visual studio code - Python Line profiler not working in VSCode - Stack Overflow

programmeradmin1浏览0评论

I've installed line_profiler 4.1.3 from conda and I'm using a jupyter notebook in VSCode.

When I run the following cells


%load_ext line_profiler

def test_fn():
    x = 2+2
    return x

lprun -f test_fn test_fn()

I receive this output:

Timer unit: 1e-07 s

Total time: 3.8e-06 s

Could not find file C:\Users\ <user>\AppData\Local\Temp\ipykernel_9076\3402019769.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.

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
     1                                           
     2         1         18.0     18.0     47.4  
     3         1         20.0     20.0     52.6

For any function I attempt to line profile I get the same warning and I don't see any of the functions contents.

This can be worked around by doing


%load_ext line_profiler

%%writefile test.py
def test_fn()
    ...

from test import test as t
lprun -f t t()

Then I get the correct output.

发布评论

评论列表(0)

  1. 暂无评论