Skip to content
ModuleNotFoundError: No module named '...'

ModuleNotFoundError: No module named '...'

DodaTech 2 min read

When Python raises ModuleNotFoundError: No module named '...', it means the import statement cannot find the requested module anywhere in the module search path.

What It Means

Python looks for modules in sys.path — a list of directories that includes the script’s directory, the standard library, and site-packages. If the module isn’t in any of these locations, this error is raised.

Why It Happens

  • The module isn’t installed (pip install needed)
  • You’re in the wrong virtual environment (or none at all)
  • The module is installed for a different Python version (e.g. Python 2 vs 3)
  • The script is running from a directory that shadows the module name
  • A custom script has the same name as the module you’re trying to import

How to Fix It

Step 1: Install the missing module

pip install <module-name>

For specific versions:

pip install <module-name>==1.2.3

Step 2: Activate your virtual environment

If you created a virtual environment but forgot to activate it:

# On Linux/macOS:
source venv/bin/activate

# On Windows:
venv\Scripts\activate

Step 3: Check Python version compatibility

Some modules only support certain Python versions:

# Check which Python you're using
python --version

# Install for your specific Python version
python3.11 -m pip install <module-name>

Step 4: Inspect the module search path

import sys
print(sys.path)

Make sure the directory containing your module appears in this list.

Step 5: Rename conflicting scripts

If you named your script the same as the module (e.g. requests.py), rename it — Python will import your script instead of the real module.

Why does pip say 'already installed' but I still get ModuleNotFoundError?
You’re likely running Python from a different environment than where pip installed the module. Check with which python and which pip — they should point to the same Python installation. Activate the correct virtual environment or use python -m pip install <module> to ensure alignment.
How do I install modules globally vs in a virtual environment?
Without an active virtual environment, pip install installs globally (or user-wide). To install in a virtual environment, first create one with python -m venv venv, activate it, then run pip install. Always prefer a virtual environment to avoid dependency conflicts.
Can I install a module for a specific Python version?
Yes. Use the explicit Python version’s pip: python3.10 -m pip install <module> or python3.11 -m pip install <module>. Alternatively, create a virtual environment with the desired Python version using python3.11 -m venv venv.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro