From f7d480e59dbe72139786b734f6da4d68abfe5513 2017-05-13 14:31:14
From: Thomas Kluyver <thomas@kluyver.me.uk>
Date: 2017-05-13 14:31:14
Subject: [PATCH] Let nbformat take care of opening the file

Notebook files should always be read as utf-8, but the default for
io.open() is to use a platform-dependent default encoding. The easiest
way around this is to pass the filename to nbformat.read() and let it
open the file correctly.

Bug identified at: http://stackoverflow.com/questions/43915006/encoding-
error-in-jupyter-when-run-another-notebook

---

diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py
index fb2745a..0a8933f 100644
--- a/IPython/core/interactiveshell.py
+++ b/IPython/core/interactiveshell.py
@@ -2501,13 +2501,12 @@ class InteractiveShell(SingletonConfigurable):
             """generator for sequence of code blocks to run"""
             if fname.endswith('.ipynb'):
                 from nbformat import read
-                with io_open(fname) as f:
-                    nb = read(f, as_version=4)
-                    if not nb.cells:
-                        return
-                    for cell in nb.cells:
-                        if cell.cell_type == 'code':
-                            yield cell.source
+                nb = read(fname, as_version=4)
+                if not nb.cells:
+                    return
+                for cell in nb.cells:
+                    if cell.cell_type == 'code':
+                        yield cell.source
             else:
                 with open(fname) as f:
                     yield f.read()