I will frequently use IPython.embed()
to examine the state of running code. In earlier versions of IPython, it correctly determines color capability of my terminal (xterm), and uses colored text. In the latest version of IPython (7.2.0), only black and white text are shown when using IPython.embed()
.
Based on the documentation, I should be able to override this default in the default profile by setting c.InteractiveShell.colors = 'Linux'
. However, this setting only applies to standalone instances of IPython, and not embedded sessions.
I can correct this for each instance by using the %colors Linux
magic method. However, this should work automatically without needing additional configuration after each embed.
If I start a standalone instance of IPython by running ipython3
directly, then the terminal colors are correctly set. However, this is not an option for my most common workflow.
This was tested using python 3.5.2, running on Linux Mint 19 (based on Ubuntu 18.04). The first ipython version on PyPI where this occurred is version 7.0.0. The previous version available, 6.5.0, correctly uses terminal colors with IPython.embed()
. For now, I have reverted to the last working version of 6.5.0, but I would like to keep up-to-date on the most recent version.
The easiest answer would be IPython.embed(colors="neutral")
From inside the embedded shell, you can type config
to get a list of the available config categories:
In [1]: config
Available objects for config:
AliasManager
DisplayFormatter
HistoryManager
IPCompleter
InteractiveShellEmbed
LoggingMagics
MagicsManager
OSMagics
PrefilterManager
ScriptMagics
You can see that InteractiveShell
is not available, but InteractiveShellEmbed
is.
The following snippet should set the colors correctly:
from IPython import embed
from traitlets.config import get_config
c = get_config()
c.InteractiveShellEmbed.colors = "Linux"
embed(config=c)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With