我使用带有 python 3.6 安装的 jupyter notebook。我创建了一个 anaconda 虚拟环境,当我在其中启动 jupyter notebook 时,%%time 命令似乎有问题。
如果我使用 %%time 命令编写一个单元格,如下所示:
%%time
a = 2
我所有的变量声明在我的以下单元格中都是未知的
print(a)
我收到以下错误:
NameError Traceback (most recent call last)
<ipython-input-3-3f786850e387> in <module>
----> 1 a
NameError: name 'a' is not defined
但是,它在我的根环境中运行良好。请帮忙。
iPython 7.3 中的行为已更改为以这种方式工作:
https://ipython.readthedocs.io/en/stable/interactive/magics.html#magic-time
所以我假设你的 root 环境必须有一个旧版本的 iPython / Jupyter notebook。
替代选项:
import time
start = time.time()
"the code you want to test stays here"
end = time.time()
print(end - start)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句