2

I found the following article: Timing and Profiling in IPython from March, 2013, but I am having problems defining and using the magics. I wonder if this is because some of the information in the article does not apply anymore.

I did:

$ pip install line-profiler
$ pip install psutil
$ pip install memory_profiler 

and then in my IPython session I defined:

import memory_profiler

def load_ipython_extension(ip):
    ip.define_magic('memit', memory_profiler.magic_memit)
    ip.define_magic('mprun', memory_profiler.magic_mprun)

When when I then try:

%memit

I get: ERROR: Line magic function not defined. Why?

Also, is the article from 2013 relevant still for IPython 2.x?

Amelio Vazquez-Reina
  • 91,494
  • 132
  • 359
  • 564

1 Answers1

1

You also need to "register the modules", as explained later in the post.

Edit ~/.ipython/profile_default/ipython_config.py, search for, uncomment, and modify these lists to include:

c.TerminalIPythonApp.extensions = [ 'line_profiler_ext', 'memory_profiler_ext', ] c.InteractiveShellApp.extensions = [ 'line_profiler_ext', 'memory_profiler_ext', ]

This worked for me, when I defined a profile and the extension folder $IPythonDIR/extensions.

Not sure, how to make this work if you manually import the functions in the interactive shell.

Jan
  • 4,932
  • 1
  • 26
  • 30