6

For the 1000th time, I am trying to install the nbextensions for my Jupyter Notebook and every time I get the error ModuleNotFoundError: No module named ‘notebook.base’.

I did everything according to the instructions; in Windows 11 cmd:

  1. installed notebook with the command pip install notebook;
  2. downloaded packages pip install jupyter_contrib_nbextensions;
  3. then I try to install these packages with the command jupyter contrib nbextension install --user. And at this step I get the error: from notebook.base.handlers import APIHandler, IPythonHandler ModuleNotFoundError: No module named ‘notebook.base’.

I have already

  • reinstalled notebook with the command pip install --upgrade --force-reinstall notebook - no result;
  • deleted and reinstalled nbextensions pip install jupyter_contrib_nbextensions - to no avail;
  • created a venv and tried to install extensions there - no;
  • cleared the cache in packages with the command pip cache purge - this didn't work out neither.
  • eventually reinstalled python again - the result is always the same.

I have the latest Python 3.11.4. Path is written in environment variables when installing Python, there I also created a PYTHONPATH variable with the path: C:\Users\Nikita\AppData\Local\Programs\Python\Python311.

Please help or advise another extension for Jupyter Notebook that would allow formatting code like autopep8.

C:\Users\Никита>jupyter contrib nbextension install --user
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\Никита\AppData\Local\Programs\Python\Python311\Scripts\jupyter-contrib.EXE\__main__.py", line 7, in <module>
  File "C:\Users\Никита\AppData\Local\Programs\Python\Python311\Lib\site-packages\jupyter_core\application.py", line 285, in launch_instance
    return super().launch_instance(argv=argv, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Никита\AppData\Local\Programs\Python\Python311\Lib\site-packages\traitlets\config\application.py", line 1041, in launch_instance
    app = cls.instance(**kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Никита\AppData\Local\Programs\Python\Python311\Lib\site-packages\traitlets\config\configurable.py", line 551, in instance
    inst = cls(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Никита\AppData\Local\Programs\Python\Python311\Lib\site-packages\jupyter_contrib_core\application.py", line 27, in __init__
    self._refresh_subcommands()
  File "C:\Users\Никита\AppData\Local\Programs\Python\Python311\Lib\site-packages\jupyter_contrib_core\application.py", line 43, in _refresh_subcommands
    get_subcommands_dict = entrypoint.load()
                           ^^^^^^^^^^^^^^^^^
  File "C:\Users\Никита\AppData\Local\Programs\Python\Python311\Lib\site-packages\pkg_resources\__init__.py", line 2471, in load
    return self.resolve()
           ^^^^^^^^^^^^^^
  File "C:\Users\Никита\AppData\Local\Programs\Python\Python311\Lib\site-packages\pkg_resources\__init__.py", line 2477, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Никита\AppData\Local\Programs\Python\Python311\Lib\site-packages\jupyter_contrib_nbextensions\__init__.py", line 5, in <module>
    import jupyter_nbextensions_configurator
  File "C:\Users\Никита\AppData\Local\Programs\Python\Python311\Lib\site-packages\jupyter_nbextensions_configurator\__init__.py", line 18, in <module>
    from notebook.base.handlers import APIHandler, IPythonHandler
ModuleNotFoundError: No module named 'notebook.base'

2 Answers2

6

The version of Jupyter Notebook you have is not suitable for installing extensions, as it became incompatible from what I could see. Therefore, you would need to use a lower version. The following version worked for me:

pip install --upgrade notebook==6.4.12

  • 1
    notebook 7 just got released and I upgraded my notebook to 7+. So do you mean to say there is no way to support extensions in notebook 7 at all? – Sayan Dey Aug 20 '23 at 11:34
  • 1
    At least from what I've seen, it seems that nbextensions are no longer supported in the current versions of Jupyter Notebook. This is because they introduced Jupyter Lab, where extensions can be obtained. – Angelo Miranda Aug 21 '23 at 02:52
  • Thanks, helpful. will migrate to lab. – Sayan Dey Aug 23 '23 at 08:35
1

Adding to Angelo's answer:

Recall that you can also create a new python environment in which to install the lower version. python -m venv <choose-a-name>. Then you can activate your environment and install the stuff you need using pip, without affecting your global python libraries. See https://docs.python.org/3/tutorial/venv.html for more info.

Joel Sjögren
  • 2,010
  • 1
  • 13
  • 12