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
Writing to sys.stdout fails on Python 3 #20
Comments
Just to clarify, this is a regression between 1.4.0 and 1.4.1, caused by this commit. Would be worth writing a test specifically to catch this when it's fixed. On 1.4.0:
(no error) On 1.4.1:
|
Thanks both. @takluyver I've just imported from IPython since that's a strong dependency anyway. @jni yes more tests would be great. I need to be a bit more vigilant about python 3. I don't use it everyday so simple things like this can slip through. |
I've released 1.4.2 with this fix. |
@aaren, thanks for the really quick fix!
Maybe you should! I made the switch just a couple of months ago and I've been pretty happy. =) |
@jni I'll switch once thesis is finished... There is lots of good stuff in python 3 so I want to switch, but at the same time I can't afford to go into a conversion rabbit hole right now! |
Be aware that that function is moving in the reorganisation for IPython/Jupyter 4.0. We've left it exposed at the old import location for backwards compatibility, so your fix should be fine through 4.x releases, but at some point we'll remove it from |
Thanks. When Jupyter is consolidated I'll switch to that. |
Just ran into this with @stefanv. This line:
aims to wrap
sys.stdout
in a unicode interface that will encode using UTF-8 before writing. But in Python 3,sys.stdout
is already a unicode interface, so it encodes and tries to write bytes to something that's expecting unicode.We have Python 2 and 3 compatible code for this in nbconvert - feel free to copy and paste our function:
https://github.com/jupyter/jupyter_nbconvert/blob/3a55808265c8b140cb483c374b5c6ccd464373d0/jupyter_nbconvert/utils/io.py#L12
You'd use this as:
The text was updated successfully, but these errors were encountered: