Comments (15)
Added the following to my IPython notebooks, and the logging messages are back. Yay! :)
# Create logger
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
# Create STDERR handler
handler = logging.StreamHandler(sys.stderr)
# ch.setLevel(logging.DEBUG)
# Create formatter and add it to the handler
formatter = logging.Formatter('%(name)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
# Set STDERR handler as the only handler
logger.handlers = [handler]
from ipykernel.
I am having the same problem... I confirm that with jupyter 4.0.6 it was working fine.
from ipykernel.
Hi, I am also having this problem, however I'm ssh tunnelling to a remote notebook server and don't have a corresponding console to capture the emits... The notebook fills with stack traces to this effect for each call to a logger in any module I've imported:
Traceback (most recent call last): File "/home/daveg/anaconda2/lib/python2.7/logging/__init__.py", line 874, in emit stream.write(fs % msg) IOError: [Errno 5] Input/output error Logged from file h5.py, line 62 Traceback (most recent call last): File "/home/daveg/anaconda2/lib/python2.7/logging/__init__.py", line 874, in emit stream.write(fs % msg) IOError: [Errno 5] Input/output error Logged from file h5.py, line 63 Traceback (most recent call last): File "/home/daveg/anaconda2/lib/python2.7/logging/__init__.py", line 874, in emit stream.write(fs % msg)
I can't comment on any previous version, but this is with ipykernel (4.3.1)
from ipykernel.
Ran into the same problem after upgrading to ipykernel=4.3.1
.
Using ipykernel=4.2.2
until this is fixed.
from ipykernel.
Confirm the issue.
I am using Anaconda distribution 2.5.0 (Python 2.7.11)
on Windows 10 Version 1607 (Build 14393.10)
. The ipython core is 4.0.3
and notebook server version is 4.1.0
from ipykernel.
Any idea what is causing this..? Spent half an hour trying to fix what I thought was a broken logging module before I remembered this issue.... :(
from ipykernel.
I think #127 should have fixed this, so when we release 4.4, workarounds should not be necessary.
I'll close this issue, but let us know if you can reproduce it with ipykernel master, or >= 4.4.
from ipykernel.
Hi: I am a jupyter newbie. From "Help" => "About" I see: notebook server 4.3.2, Python 2.7.6, IPython 5.2.2 . I am running jupyter inside a docker. I have the same problem. Everything works fine until I execute reload(sys)
. After that, output goes to the console instead of cells. This simpler workaround works for me. However, executing help()
makes the output disappear again, and the above workaround does not help.
from ipykernel.
Why do you think you need reload(sys)
? Doing that is generally not advised, and is expected to break things.
from ipykernel.
I wanted to use graphviz, so I did:
with open('study-map.dot', 'r') as myfile:
data=myfile.read()
from graphviz import Source
src = Source(data)
src
But got this error:
UnicodeDecodeError Traceback (most recent call last)
/usr/local/lib/python2.7/dist-packages/IPython/core/formatters.pyc in __call__(self, obj)
309 method = get_real_method(obj, self.print_method)
310 if method is not None:
--> 311 return method()
312 return None
313 else:
/usr/local/lib/python2.7/dist-packages/graphviz/files.pyc in _repr_svg_(self)
81
82 def _repr_svg_(self):
---> 83 return self.pipe(format='svg').decode(self._encoding)
84
85 def pipe(self, format=None):
/usr/local/lib/python2.7/dist-packages/graphviz/files.pyc in pipe(self, format)
94 format = self._format
95
---> 96 data = text_type(self.source).encode(self._encoding)
97
98 outs = backend.pipe(self._engine, format, data)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe5 in position 63: ordinal not in range(128)
<graphviz.files.Source at 0x7f0a744bff90>
So then I followed this and added this:
import sys
#stdout = sys.stdout
reload(sys)
sys.setdefaultencoding('utf8')
#sys.stdout = stdout
(The two commented lines were added afterwards, to take stdout back to jupyter cells from the console.)
What would be the correct way of asking jupyter to treat strings as utf8 after it has started then? Or can it only be done before jupyter is started? (I am not quite familiar with python, either ^_^)
from ipykernel.
The error there is coming from inside the graphviz package. I suspect the author hasn't been very careful with bytes and unicode - you may want to file a bug on that project about it.
I'd guess that you can work around it by replacing your open()
call with:
import io
with io.open('study-map.dot', 'r', encoding='utf-8') as myfile:
Then the data you read from the file will be a unicode string rather than a bytes string.
from ipykernel.
Thank you, @takluyver. It works!
However, I find it rather confusing about the system default encoding and the enforcement against changing it. First, the error pops up when doing I/O, not when graphviz parsing the content, so I suspect it has more to do with I/O than with graphviz. Secondly, with 2.7.12 in my working env, sys.getdefaultencoding()
prints 'ascii' and yet myfile.read()
(without encoding='utf-8'
) was successful. On the other hand with jupyter in a docker, sys.getdefaultencoding()
prints 'utf-8' and yet myfile.read()
(without encoding='utf-8'
) was unsuccessful.
So I just have to leave the bug report to someone more knowledgeable and remember to add encoding='utf-8'
from now on as a sure bet.
ps. I have carelessly destroyed my previous docker env since last comment. This comment refers to a different jupyter version: jupyter 4.3.1 Python 3.5.2 IPython 5.1.0 . Here is the new error message:
UnicodeDecodeError Traceback (most recent call last)
<ipython-input-22-f358fa348e73> in <module>()
1 # https://github.com/rainyear/lolita/issues/30
2 with open('study-map.dot', 'r') as myfile:
----> 3 data=myfile.read()
4 from graphviz import Source
5 src = Source(data)
/opt/conda/lib/python3.5/encodings/ascii.py in decode(self, input, final)
24 class IncrementalDecoder(codecs.IncrementalDecoder):
25 def decode(self, input, final=False):
---> 26 return codecs.ascii_decode(input, self.errors)[0]
27
28 class StreamWriter(Codec,codecs.StreamWriter):
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe5 in position 63: ordinal not in range(128)
from ipykernel.
It is a bit confusing. Specific bits:
- In Python 2, unicode errors can pop up almost anywhere. Python 3 makes it generally more consistent and predictable, though it's more strict, so you sometimes get errors with things that work (or appear to work) in Python 2.
- There are a few different 'default' encodings for different situations. The one from
sys.getdefaultencoding()
is used when you dou'...'.encode()
orb'...'.decode()
. There's a separate, platform dependent default encoding for reading data from files. That's apparently 'ascii' in your Python 3 docker container. In general, it's best not to rely on this default, but rather to explicitly passencoding=
when opening text files.
from ipykernel.
logging messages didn't even show in the terminal, but the work-around worked for me ;
ipykernel : 5.6.0
jupyter : 4.4.0
jupyter lab : 0.32.1
from ipykernel.
Unfortunately the work around suggested by ostrokach does not work for me.
python 2.7.15
ipykernel 4.10.0
jupyter_core 4.4.0
:(
from ipykernel.
Related Issues (20)
- jupyther
- Should ipykernel align kernel SVG with the one used by JupyterLab?
- CI failing with INTERNALERROR when skipping tests
- Jupyter notebook cell instruction after asyncio.run is not executing with 6.28.0v of ipykernel HOT 4
- Can not install ipykernel HOT 2
- Better cell magic by removing some of the syntax limitations
- python 3.11 debugpy error messages HOT 3
- Directing output of out external threads/processes to specific cells HOT 1
- Qt eventloop interferes with asyncio.call_later in _abort_queues HOT 7
- Incorrect stack traceback when try except finally is used in jupyter notebooks with pandas
- Feature request: enable editing_mode = ‘vi’ for a ZMQTerminalIPythonApp console
- TypeError: '>=' not supported between instances of 'str' and 'datetime.datetime' HOT 3
- Release 7.0 HOT 5
- "ModuleNotFoundError: No module named 'comm'" when running 'python -m ipykernel install'
- Output [ ] Alone HOT 2
- Compatibility with pytest 8 HOT 1
- Different child termination behavior during Kernel shutdown on Posix and Windows systems HOT 1
- Windows: ipykernel install prefix not usable for c:\programdata\jupyter
- AnyIO commit breaks Matplotlib display in separate windows HOT 2
- Restore to previous state with copy-on-write HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ipykernel.