python - Jupyter Notebook:%%time 魔法丢失全局变量
问题描述
在 jupyter 单元格内声明的变量%% time
不会显示在后续单元格中。
In [1]: %%time
a = 2
In [2]: print(a)
NameError Traceback (most recent call last)
<ipython-input-5-bca0e2660b9f> in <module>
----> 1 print(a)
NameError: name 'a' is not defined
这是一个错误还是设计使然?我不记得以前遇到过这个问题。
我在 Windows 10 上使用 Python 3.7.3 和 Jupyter 4.4.0 和 IPython 7.4.0。
解决方案
对于以后遇到这个问题的人来说,这是 Ipython 7.4 中的一个错误。错误报告在这里 - https://github.com/ipython/ipython/issues/11659
它在 Ipython 7.5 中得到修复。
使用将 ipython 更新到 7.5conda update ipython
解决了该问题。
推荐阅读
- json - 使用通配符键从 JSON 快速解码
- r - 如何在R中分解数据帧
- java - 列表已损坏且未添加
- flutter - 如何为 AlertDialog 颤振禁用 onBackPressed()
- swiftui - 如何通过swiftui中的事件更改图像的样式?
- android-layout - PDF 查看器与 Web 查看器 Android
- reactjs - useContext 值未定义
- python - 基于令牌的授权导致未经授权的 401
- apache-flink - Flink 流加入可能返回大结果集的维度表
- spring - MultiValueMap casuing issue application/json;charset=UTF-8 not supported