Interactive Python: cannot get `%lprun` to work, although line_profiler is imported properly

限于喜欢 提交于 2019-12-02 17:04:25

You have two ways to make work %lprun, one solution is temporal, i.e., it lasts until you finish your ipython session, and the other one is permanent.

Temporal: (as Carlos Cordoba's answer)

After starting ipython run the following:

In [1]: %load_ext line_profiler

Permanent:

Add the following lines to ~/.ipython/profile_default/ipython_config.py:

c.TerminalIPythonApp.extensions = [
    'line_profiler',
]

If you don't have the file ~/.ipython/profile_default/ipython_config.py, you can create it by (see this for more info):

ipython profile create

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!