python - conda 虚拟环境中的 Jupyter 魔术命令 %%time 错误
问题描述
我使用 jupyter notebook 和 python 3.6 安装。我创建了一个 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
所以我假设你的根环境必须有旧版本的 iPython / Jupyter notebook。
备选方案:
import time
start = time.time()
"the code you want to test stays here"
end = time.time()
print(end - start)
推荐阅读
- java - Java 字符串数组迭代:有什么方法可以让这更简单吗?
- pandas - 熊猫枢纽和集团
- solidity - 为什么我的转会费不能稳定运行
- apache-camel - 如何修复在 POM 中引发错误的 cxf-codegen-plugin
- location - 我的设备阻止了 expo go 中的所有权限
- discord.py - Discord.py 按钮(未嵌入)
- python - 根据另一列的日期和类别创建数据排名
- api - 使用 Airflow API 进行 JWT 身份验证
- flutter - 从 Internet 下载工件时出错
- javascript - 使用 CSS 在显示普通文本字段和输入之间进行切换