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

29.1k Views Asked by At

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'
6

There are 6 best solutions below

0
Ajinkya Nawarkar On BEST ANSWER

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
5
Angelo Miranda On

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
0
Joel Sjögren On

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.

1
Коломец Денис On

I solved it from Anaconda Powershell Prompt using the following commands:

$ conda install -c conda-forge jupyter_contrib_nbextensions
$ conda install -c "conda-forge/label/cf201901" jupyter_contrib_nbextensions
$ conda install -c "conda-forge/label/cf202003" jupyter_contrib_nbextensions

Looking for https://anaconda.org/conda-forge/jupyter_contrib_nbextensions

1
telos On

@Ajinkya Nawarkar's additional answer also fixes this problem:

TypeError: warn() missing 1 required keyword-only argument: 'stacklevel'

Do this:

pip uninstall traitlets
pip install traitlets==5.9.0
0
Shirley Ow On

In addition to Ajinkya's answer, after downgrading traitlets, will also have to downgrade ipython to a compatible version.

pip uninstall ipython
pip install ipython==8.9.0