pip install memory-profiler
from memory_profiler import profile # @profile(precision=4, stream=open('memory_profiler.log','w+')) @profile def func(): ... ... if __name__=='__main__': func()