### Install memory_profiler via pip Source: https://github.com/pythonprofilers/memory_profiler/blob/master/README.rst This command installs or upgrades the memory_profiler package using pip, the standard Python package installer. Ensure you have pip installed and updated for the best experience. ```bash pip install -U memory_profiler ``` -------------------------------- ### Install memory_profiler for IPython Source: https://github.com/pythonprofilers/memory_profiler/blob/master/README.rst This snippet shows how to integrate memory_profiler with IPython versions prior to 0.10 by modifying the user configuration file. It imports the necessary IPython API and loads the memory_profiler extension. ```python # These two lines are standard and probably already there. import IPython.ipapi ip = IPython.ipapi.get() # These two are the important ones. import memory_profiler memory_profiler.load_ipython_extension(ip) ``` -------------------------------- ### Set memory tracking backend via API Source: https://github.com/pythonprofilers/memory_profiler/blob/master/README.rst Illustrates how to set the memory tracking backend programmatically when using the memory_profiler API. This example shows the usage of the `memory_usage` function with the `backend` parameter. ```python from memory_profiler import memory_usage mem_usage = memory_usage(-1, interval=.2, timeout=1, backend="psutil") ``` -------------------------------- ### Run and Plot Memory Usage with mprof Source: https://github.com/pythonprofilers/memory_profiler/blob/master/README.rst This snippet demonstrates how to use the `mprof` command-line tool to run a Python script and plot its memory usage. It requires the `memory_profiler` library to be installed. The output is a plot generated using matplotlib. ```bash mprof run --python python