To make %lprun
work, you need to load the extension into your session, using this command:
In [1]: %load_ext line_profiler
Check out this notebook to see some examples that use the magic.
Besides, if you are working with Spyder, there is also a third-party line_profiler
plugin, which you can find here.