%mprun不断给出nameerror(导入模块的问题)

时间:2018-12-27 19:10:06

标签: python memory jupyter memory-profiling

嗨,我目前正在尝试为我的一项功能执行逐行内存配置文件。但是,无论何时该功能需要导入的模块,%mprun命令都不起作用。这是一个简化的示例。我在jupyter,命令提示符和anaconda提示符下都尝试过。

#Here I write a py file containing the function I want to profile
%%file mpruntest.py
@profile
import pandas as pd
import numpy as np

def test(a):
    df = pd.DataFrame(np.random.randn(10,5))
    return df

这会给我一个名为mpruntest的py文件。

#Here I run the mprun
from mpruntest import test
%mprun -f test test(1)

我不断收到NameError,指出未定义pd或np。我不确定该怎么做才能使内存分析器正常工作并读取相关模块的导入。

0 个答案:

没有答案