Skip to main content
 首页 » 编程设计

python 木星 : `%run -d` (debug mode) doesn't work

2025年02月15日10telwanggs

我正在尝试使用神奇的 %run -d "/home/dev/filename.py" 在 Debug模式下在 Jupyter Notebook 中运行脚本。

我在这样做时收到错误:AttributeError: 'NoneType' object has no attribute 'f_globals'。

如果 filename.py 只包含 print("hello world),就会发生这种情况。脚本本身是无关紧要的,错误发生在调用魔法时。

需要明确的是,产生错误的代码是神奇的 %run -d 本身。您可以尝试使用任何脚本在 Jupyter Notebook 中重现它。对我来说,任何脚本都会返回该错误。

有人遇到过同样的情况吗?知道发生了什么吗?

请您参考如下方法:

好的,我找到了: https://github.com/ipython/ipython/pull/10030 https://github.com/takluyver/ipython/commit/6b1960d811d25e8f754324259a5b4fd59f8f8162

这是我必须手动编辑的 Ipython 文件中的错误。对于新手来说不是最简单的:S。