我正在尝试在 IPython 中进行文件分析,生成一些分析统计输出,然后将其传递给一些 Python 分析 GUI 工具,如 KCachegrind。这是我试图做到这一点的代码。所有代码都在 IPython 中执行。
# example function for profiling
def factorial(n):
if n == 0:
return 1.0
else:
return float(n) * factorial(n-1)
def taylor_sin(n):
res = []
for i in range(n):
if i % 2 == 1:
res.append((-1)**((i-1)/2)/float(factorial(i)))
else:
res.append(0.0)
return res
# generate cProfile output (the stats, not the text)
%prun -D prof.out x = taylor_sin(500)
# do conversion using pyprof2calltree
# to do it in IPython, add prefix '!' to code to make it Shell-command code
!pyprof2calltree -i prof.out -o prof.calltree
现在 IPython 会打印一条错误消息:
!pyprof2calltree -i prof.out -o prof.calltree
/bin/sh: 1: pyprof2calltree: not found
这是说我没有添加pyprof2calltree
到环境路径或类似的东西吗?如何解决?
我可以在纯 shell 命令中完美地运行它。但我不喜欢在 IPython 和终端之间频繁切换,我只想在 IPython 中完成所有工作。我知道添加前缀!
会使代码像在 shell 命令中一样运行,但为什么它会向我提出如上所示的错误?
Jian@Home-PC:~/Dropbox/Coding/Python$ pyprof2calltree -i prof.out -o prof.calltree
writing converted data to: prof.calltree
Jian@Home-PC:~/Dropbox/Coding/Python$
IPython 与 Anaconda py3.4 一起安装;操作系统 Ubuntu 14.04;pyprof2calltree
通过 pip 安装