2

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

pauljohn32
  • 2,079
  • 21
  • 28
  • 1
    The link points to a non-existent page because v5.7.6 docs don't contain the examples section you point to - your link is for 4.x, it's quite old. IIUC this is the page you are looking for: https://jupyter-notebook.readthedocs.io/en/5.7.6/examples/Notebook/Importing%20Notebooks.html – Błażej Michalik Apr 06 '21 at 03:50
  • Thanks for the link. I'll study the change from 4.x to 5.7.6, and report back. – pauljohn32 Apr 06 '21 at 18:35

1 Answers1

4

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) 
Błażej Michalik
  • 4,474
  • 40
  • 55