Ipython: Colored prompt for embed()

Created on 4 Dec 2018  ·  10Comments  ·  Source: ipython/ipython

import IPython; IPython.embed() has no colors for me. https://github.com/ipython/ipython/issues/9450 is related but old.

IPython 7.1.1
Python 3.6.6
Ubuntu 18.04

Most helpful comment

For anyone who stumbles across this, I was able to fix it just like this:

IPython.embed(colors="neutral")

All 10 comments

Same here.

iPython 7.1.1
Python 3.7.0,
Mac OS X 10.14

Also here.

IPython 7.2.0
Python 3.6.6
RHEL 7.4 / Mac OS 10.14

It seems that this issue originates from #11265.

https://github.com/ipython/ipython/blob/0acd580fce7192044a6f846dd09d31d498018347/IPython/terminal/embed.py#L369-L371

Why is the default now to implicitly assign colors to 'NoColor'?

For a dirty fix, I set

IPython.embed(using=False)

which is obviously abusing code, and uses the IPython.core.async_helpers._AsyncIORunner instead of IPython.core.async_helpers._pseudo_sync_runner. For my particular case I'm not sure what unintended side effects that may have.

We're also hitting this issue, which is one of the things preventing us from upgrading from 5.x... We'd really appreciate a fix for this issue.

Yes, this is weird behavior. In my case the whole config is overwritten without @topherocity 's solution

Seems to still be an issue.

Still an issue on both Windows and Linux. BTW you can use %colors linux or %colors lightbg before this is fixed.

Still an issue on both Windows and Linux. BTW you can use %colors linux or %colors lightbg before this is fixed.

@Arnie97 Could you elaborate on that? I don't know what you mean about "use %colors linux".

Type '%colors linux' in the embedded terminal, and press enter.

For anyone who stumbles across this, I was able to fix it just like this:

IPython.embed(colors="neutral")

Thank @banool!

I hope this may help others as well but here is the list of color choices that come default. This is taken from the Exception that is raised if you try to use a non-supported color trait.

The 'colors' trait of an InteractiveShellEmbed instance must be any of ['Neutral', 'NoColor', 'LightBG', 'Linux'], but a value of True <class 'bool'> was specified

For another example using the "Linux" colors trait. I get a nice shiny colored terminal using Linux colors.

$ python -c 'import IPython; IPython.embed(colors="Linux")'
Python 3.7.4 (default, Aug 13 2019, 15:17:50) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.8.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]:    
Was this page helpful?
0 / 5 - 0 ratings

Related issues

jakirkham picture jakirkham  ·  4Comments

frenzymadness picture frenzymadness  ·  3Comments

gregcaporaso picture gregcaporaso  ·  3Comments

quchunguang picture quchunguang  ·  3Comments

RinaldoB picture RinaldoB  ·  3Comments