Skip to content

Resolving ModuleNotFoundError: No module named 'jupyter_server.contents'

Problem Statement

When launching Jupyter Notebook, users encounter this critical error preventing startup:

ModuleNotFoundError: No module named 'jupyter_server.contents'
Traceback (most recent call last):
...
TypeError: warn() missing 1 required keyword-only argument: 'stacklevel'

The error occurs due to version conflicts between Jupyter components, specifically:

  1. Missing dependencies in the notebook package
  2. Incompatible versions of the traitlets library
  3. Version conflicts after recent package updates

The core issue originates from breaking changes in Jupyter ecosystem packages, particularly notebook and traitlets, creating a compatibility gap when the required module jupyter_server.contents becomes inaccessible.

Solutions

Recommended Modern Fix (Post-2023)

Install a patched version of the notebook package (v6.5.6 or newer):

bash
# Install specific fixed version
pip install notebook==6.5.6
bash
# Install latest compatible 6.x version
pip install --upgrade --no-cache-dir "notebook>=6.5.6,<7"

Why this works

Version 6.5.6+ contains compatibility fixes addressing the missing jupyter_server.contents module. The --no-cache-dir flag prevents installation of corrupted cached packages.

Legacy Workaround (For Older Environments)

If notebook upgrades aren't feasible, downgrade traitlets:

bash
pip uninstall traitlets
pip install traitlets==5.9.0

Caution

This should only be used temporarily, as locking traitlets to old versions causes compatibility issues with other libraries.

Verification Steps

Confirm successful resolution:

bash
# Check installed versions
pip show notebook traitlets

# Start Jupyter to verify
jupyter notebook

::: success Expected Output

Name: notebook
Version: 6.5.6
...
[I xx:xx:xx.xxx NotebookApp] Serving notebooks from local directory: ...

:::

Prevention Best Practices

  1. Always pin dependencies in requirements.txt:

    txt
    notebook==6.5.6
    jupyter_server==2.*
  2. Create isolated environments using virtualenv/conda:

    bash
    python -m venv jupyter-env
    source jupyter-env/bin/activate
    pip install notebook==6.5.6
  3. Update judiciously using compatibility-tested versions:

    bash
    pip install -U "notebook>=6.5.6,<7" "jupyter_server>=2,<3"

Version Guidance

PackageSafe Version RangeUnsafe Versions
notebook>=6.5.6, <75.10.0, 6.0-6.5
traitlets>=5.9.0, <65.10.0