我发现了以下文章:2013年3月的IPython中的时序和特征分析,但是我在定义和使用魔法时遇到了问题。我不知道这是不是因为文章中的一些信息不再适用了。
我做了:
$ pip install line-profiler
$ pip install psutil
$ pip install memory_profiler 然后在我的IPython会话中,我定义了:
import memory_profiler
def load_ipython_extension(ip):
ip.define_magic('memit', memory_profiler.magic_memit)
ip.define_magic('mprun', memory_profiler.magic_mprun)当我试着:
%memit
我明白了:ERROR: Line magic function not defined。为什么?
另外,2013年的文章还与IPython 2.x相关吗?
发布于 2014-04-03 09:08:46
您还需要“注册模块”,如后面的文章所解释的那样。
编辑~/.ipython/profile_default/ipython_config.py,搜索、取消注释并修改这些列表,包括: c.TerminalIPythonApp.extensions = 'line_profiler_ext','memory_profiler_ext',c.InteractiveShellApp.extensions = 'line_profiler_ext','memory_profiler_ext',
当我定义了一个概要文件和扩展文件夹$IPythonDIR/extensions时,这对我起了作用。
不确定,如果您手动导入交互式shell中的函数,如何使其工作。
https://stackoverflow.com/questions/22186709
复制相似问题