如何更改 iPython 错误突出显示颜色

mar*_*jop 19 ipython

我在 macOS 中将 IPython 与 iterm2 一起使用。我以前从未遇到过配色方案的问题,但这次出现异常时,它会突出显示颜色组合中的某些部分,我发现这些部分很难阅读。我尝试过在 iterm 中使用不同的颜色设置,并在文件中进行调整highlighting_stylecolorsipython_config.py运气不佳。我已经看到有一个选项可以设置特定的颜色highlighting_style_overrides,但我没有幸运地找到合适的 pygments 选项。

Position下文。这是我所实现的最佳对比度设置,但我仍然发现在不聚焦的情况下很难阅读。

在此输入图像描述

Ale*_*inu 17

注意:使用下面 Evan Grim 的答案来实现持久配置,而无需触及包文件。


关于此有一个未解决的问题:https ://github.com/ipython/ipython/issues/13446

这是引入此更改的提交:

https://github.com/ipython/ipython/commit/3026c205487897f6874b2ff580fe0be33e36e033

要获取系统上的文件路径,请运行以下命令:

import IPython, os
os.path.join(os.path.dirname(IPython.__file__), 'core/ultratb.py')
Run Code Online (Sandbox Code Playgroud)

最后,打开文件并查找:

style = stack_data.style_with_executing_node(style, "bg:ansiyellow")
Run Code Online (Sandbox Code Playgroud)

目前,您可以通过更改bg:ansiyellow为最适合您的配色方案的内容来手动修补它,例如bg:ansiredbg:#ff0000


Eva*_*rim 15

这里有一个选项,您可以ipython_config.py将鸭拳放入更好的背景颜色中:

try:
    from IPython.core import ultratb
    ultratb.VerboseTB._tb_highlight = "bg:ansired"
except Exception:
    print("Error patching background color for tracebacks, they'll be the ugly default instead")
Run Code Online (Sandbox Code Playgroud)

已验证可使用IPython版本8.7.0