Issue
I'm working with the example code for importing an IPython (Jupyter) notebook,
Importing Notebooks. The example code still runs fine, however it generates a warning that I would like to understand and fix:
site-packages/nbformat/current.py:15: UserWarning: nbformat.current is deprecated.
- use nbformat for read/write/validate public API
- use nbformat.vX directly to composing notebooks of a particular version
warnings.warn("""nbformat.current is deprecated.
This warning has been discussed since 2015, at least, and yet I cannot find any constructive advice about what to do about it. Is this a warning that can be addressed by fixing code, or is it a function that will disappear from IPython without a replacement?
If you follow the link to the IPython blog, they claim that there is a newer version, but their link points to a non-existent page.
This code example is widely discussed in other threads in Stack Overflow, for example
python access functions in ipython notebook
Solution
Keep in mind the example you've linked up is for a much older version of Jupyter - 4.x. The page with these examples has been relocated at some point, and for the 5.7.6 version of Jupyter (the most recent as of writing this) it's located here.
First, replace the from IPython.nbformat import current
import with from nbformat import read
Then, replace this part of the 4.x snippet:
with io.open(path, 'r', encoding='utf-8') as f:
nb = current.read(f, 'json')
with the newer version:
with io.open(path, 'r', encoding='utf-8') as f:
nb = read(f, 4)
Answered By - Błażej Michalik
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.