Search code examples
python-3.xjupyter-notebookmodulenotfounderrorjupyter-contrib-nbextensions

ModuleNotFoundError: No module named 'notebook.base' when installing nbextensions


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'

Solution

  • Adding to what Angelo said above:

    After re-installing notebook: pip install --upgrade notebook==6.4.12

    You may see an error around traitlets, please change the version here as well:

    pip uninstall traitlets
    pip install traitlets==5.9.0