康达虚拟环境中的Jupyter Magic命令%% time越野车

时间:2019-05-15 09:16:59

标签: python anaconda jupyter

我将jupyter notebook与python 3.6安装在一起使用。我创建了anaconda虚拟环境,当在其中启动jupyter笔记本时,%% 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

但是,它在我的根环境中也可以正常工作。请帮忙。

1 个答案:

答案 0 :(得分:1)

iPython 7.3中的行为已更改为以这种方式工作:

https://ipython.readthedocs.io/en/stable/interactive/magics.html#magic-time

因此,我假设您的根环境必须具有旧版本的iPython / Jupyter笔记本。

替代选项:

import time
start = time.time()

"the code you want to test stays here"

end = time.time()
print(end - start)