-
Notifications
You must be signed in to change notification settings - Fork 199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Jupyter Stderr #77
Comments
is |
That's right, only stderr. This makes sense since |
aha
youre actually the first one to express a desire here. when others express the same, ill add it to the readme or ill include this as an example in the forthcoming overhaul to icecream's output. see #31 does |
Surprised I'm the first one! I would imagine most data scientists who work with Jupyter would run into this, but maybe I'm wrong.
|
future reader of this thread: if you want a way to print to stdout highlighted, like in the readme, please let us know! thank you, @Mathemmagician! 👐 |
Had the same issue with the Xonsh shell, this fixed it, thanks :) . |
this means the issue lies in writing to stderr, not (afaict) in the underlying icecream library itself @jerabaul29 what behavior do you observe, exactly, with icecream outputting to stderr in xonsh? was it slow? did output stutter? if possible, can you take a video and share it here so i can see what you see? perhaps the best path for icecream is to try to detect (how?) when icecream runs in an environment where stderr has issues. then, in such an environment, write to stdout instead of stderr |
Sorry for the late reply. As said, using |
Hey, while this technically solves the issue, it would be nice to have colorful printing on Jupyter by default. |
I found a work around for the coloring problem that plays nice with Jupyer Lab. I simply added the following to the top of my notebook: try:
from icecream import ic, colorize as ic_colorize
ic.configureOutput(outputFunction=lambda s: print(ic_colorize(s)))
ic('Hey, icecream is installed and working.')
except ImportError: # Graceful fallback if IceCream isn't installed.
ic = print
ic('Using work around as icecream is not installed.') I suggest you either add this to the documentation or even better autodetcte if the script is running on Jupyter and auto change to stdout. Aparently this function works: (got from https://stackoverflow.com/questions/15411967/how-can-i-check-if-code-is-executed-in-the-ipython-notebook ) def isnotebook():
try:
shell = get_ipython().__class__.__name__
if shell == 'ZMQInteractiveShell':
return True # Jupyter notebook or qtconsole
elif shell == 'TerminalInteractiveShell':
return False # Terminal running IPython
else:
return False # Other type (?)
except NameError:
return False # Probably standard Python interpreter |
I'm not sure that this is 100% the proper way to interface with the Jupyter/IPython API? I was trying out import IPython
ic.configureOutput(outputFunction = IPython.lib.pretty.RawText) This did break colorizing the output ... I suspect that interfacing directly with the IPython API is the "right" way to ensure that output works both in the IPython console REPL and also in Jupyter notebooks ... https://ipython.readthedocs.io/en/stable/api/generated/IPython.lib.pretty.html |
Since ic outputs to stderr, it displays weirdly in Jupyter, especially when the cell is both printing and ic-ing a lot of stuff at the same time, I've observed the order of output to be inconsistent at times. Would be nice to be able to redirect to stdout instead.
Maybe something like:
After digging deeper, I found out that what I'm looking for can be accomplished with:
It took me a while to figure it out, so I'm sure there are others. Should probably be added to the README as an example showing to how to redirect to stdout instead of stderr. Although, the line above is quite long, something shorter would be nicer.
P.S. Jupyter inconsistency can be achieved with:
outputs with messed up order:
Adding
flush=True
solves it, but obviously rather just have everything in stdout instead.The text was updated successfully, but these errors were encountered: