High severity beginner · Fix: 2-5 min

ModuleNotFoundError

builtins.ModuleNotFoundError

What this error means
Python raises ModuleNotFoundError because the 'mcp' package is not installed or not found in the environment.

Stack trace

traceback
Traceback (most recent call last):
  File "app.py", line 1, in <module>
    import mcp
ModuleNotFoundError: No module named 'mcp'
QUICK FIX
Run 'pip install mcp' in your active Python environment to install the missing package immediately.

Why it happens

This error occurs when Python cannot find the 'mcp' module in the current environment. Usually, this means the package is not installed or the environment is misconfigured. It can also happen if the package is installed in a different Python environment than the one running the code.

Detection

Check for ModuleNotFoundError exceptions during import statements and verify if 'mcp' is installed by running 'pip show mcp' or 'pip list'.

Causes & fixes

1

The 'mcp' package is not installed in the current Python environment.

✓ Fix

Run 'pip install mcp' in the active environment to install the package.

2

The code is running in a different Python environment than where 'mcp' was installed.

✓ Fix

Ensure you activate the correct virtual environment or use the same Python interpreter where 'mcp' is installed.

3

Using a system Python without user site packages and 'mcp' installed only for the user.

✓ Fix

Install 'mcp' globally or run Python with the '--user' flag or configure PYTHONPATH to include user site packages.

Code: broken vs fixed

Broken - triggers the error
python
import mcp  # This line raises ModuleNotFoundError if 'mcp' is not installed
Fixed - works correctly
python
import os
import mcp  # Fixed by installing 'mcp' package via pip

# Example usage
print('MCP module imported successfully')
Installed the 'mcp' package in the environment so Python can find and import it without error.

Workaround

If you cannot install 'mcp' immediately, mock the module in your code using 'sys.modules' to avoid import errors temporarily.

Prevention

Use virtual environments consistently and document dependencies in requirements.txt or pyproject.toml to ensure all packages like 'mcp' are installed before running code.

Python 3.7+ · mcp >=0.1.0 · tested on 0.1.x
Verified 2026-04
Verify ↗

Community Notes

No notes yetBe the first to share a version-specific fix or tip.