Search code examples
python-3.xjupytermemory-profiling

mprun magic command gets ERROR: Could not find file /tmp/ipykernel_75919/1494889556.py


I need to do a memory use profiling of a function. I'm using a jupyter notebook in with Python 3.8.10, and I've insalled succesfully the memory_profiler 0.60 with no errors. When I load the memory_profiler, using %load_ext memory_profiler, no error appears, but when I try to use mprun (%mprun -f suma2 suma2(0.2,0.2)), then this error appears:

ERROR: Could not find file /tmp/ipykernel_75919/1494889556.py

Here you have a screenshot of the whole code: enter image description here


Solution

  • I believe profiling functions defined within a jupyter notebook with %mprun is still not supported. You will have to define your function in a separate python file and import it to your jupyter notebook to memory profile it.

    E.g. in your instance, you would create a file funcy.py:

    def suma2(a,b):
        return a+b
    

    and then import it in the notebook:

    from funcy import suma2
    

    which you then can follow up with the memory profiler code.