0

我已经尝试了建议的内容。在最简单的代码上,我得到了其他人提到的熟悉的错误。错误是:

@profile
NameError: name 'profile' is not defined

在最小的代码上:

@profile
def hello():
  print('Testing')

hello()

从命令行:

kernprof -l hello.py

我已经导入future,甚至从我的 virtualenv 之外的发行版安装。这是之前的建议,就像导入未来的模块一样。

所以

import future
import cProfile

@profile
def hello():
  print('Testing')

hello()

也给出了同样的错误。我无法让这个 line profiler 与 pip 一起使用,甚至无法从原始存储库中使用。我的版本是:

pip 8.1.2
python 2.7
4

2 回答 2

0

我修复了这个问题,我从https://github.com/rkern/line_profiler克隆代码并重建,然后从二进制安装位置调用 kernprof。

于 2016-06-21T11:22:39.810 回答
-1

您可以在 python 文件的开头添加以下代码段:

import line_profiler
profile = line_profiler.LineProfiler()
于 2019-04-09T20:16:41.197 回答