Skip to content

Resolving ModuleNotFoundError for notebook.base When Installing Jupyter nbextensions

Problem Statement

When attempting to install Jupyter Notebook extensions (nbextensions) using jupyter contrib nbextension install --user, you encounter a critical error:

python
ModuleNotFoundError: No module named 'notebook.base'

This error occurs despite following official installation steps:

  1. Installing Jupyter Notebook (pip install notebook)
  2. Installing nbextensions (pip install jupyter_contrib_nbextensions)
  3. Running the nbextensions installer (jupyter contrib nbextension install --user)

Common troubleshooting steps like reinstalling packages, clearing caches, or creating virtual environments fail to resolve the issue. The core problem stems from version incompatibilities between Jupyter Notebook components and the nbextensions package.

Root Cause

The error originates from recent architectural changes in Jupyter Notebook (version 7.0+). The notebook.base module was removed in newer releases, breaking compatibility with the current version of jupyter_contrib_nbextensions. Specifically:

  • Newer notebook versions ≥7.0 lack the notebook.base.handlers module
  • jupyter_contrib_nbextensions hasn't been updated to accommodate these changes
  • Dependency conflicts between traitlets, ipython, and notebook exacerbate the issue

Solutions

Compatibility is restored by installing specific package versions:

bash
pip uninstall notebook traitlets jupyter
pip install notebook==6.4.12 traitlets==5.9.0
pip install jupyter_contrib_nbextensions --no-deps

After installation, run the nbextensions installer:

bash
jupyter contrib nbextension install --user

DEPENDENCY NOTES

If you encounter TypeError: warn() missing 1 required keyword-only argument: 'stacklevel', also downgrade ipython:

bash
pip uninstall ipython
pip install ipython==8.9.0

2. Conda Installation Method

For Anaconda/miniconda users, install from conda-forge:

bash
conda install -c conda-forge notebook jupyter_contrib_nbextensions
jupyter contrib nbextension install --user

CONDA TROUBLESHOOTING

If dependencies conflict, update your base environment first:

bash
conda update --all

3. Virtual Environment Setup

Isolate compatible packages using a virtual environment:

bash
python -m venv jupyter_env
source jupyter_env/bin/activate  # Linux/macOS
jupyter_env\Scripts\activate    # Windows
pip install notebook==6.4.12 traitlets==5.9.0 jupyter_contrib_nbextensions

VERSION COMPATIBILITY

The tested working configuration uses:

  • notebook==6.4.12
  • traitlets==5.9.0
  • jupyter_contrib_nbextensions==0.7.0

Alternative Code Formatting Extensions

Since the initial query mentions alternative code formatters, consider these nbextensions compatible with Notebook 6.4.12:

  1. Code Prettify
    Install via nbextensions configurator:

    bash
    jupyter nbextension enable code_prettify/code_prettify
  2. Autopep8 Extension
    Install and activate:

    bash
    pip install autopep8
    jupyter nbextension enable autopep8/main
  3. jupyter-black
    Install and enable:

    bash
    pip install jupyter-black
    jupyter nbextension enable jupyter-black-master/jupyter-black

Verification

Confirm successful installation:

bash
jupyter nbextension list

Expected output should include:

jupyter-black-master/jupyter-black  enabled 
- Validating: OK
code_prettify/code_prettify  enabled
- Validating: OK