[Python] Python Line profiler not working in VSCode

Discussão em 'Python' iniciado por Stack, Fevereiro 10, 2025.

  1. Stack

    Stack Membro Participativo

    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.

    Continue reading...

Compartilhe esta Página