ModuleNotFoundError: No module named 'sklearn'

Fix 'No module named sklearn' after installing scikit-learn

You installed scikit-learn but Python still can't find it. Here's why—and how to fix it in three steps, from a 30-second check to a deeper environment reset.

Why this happens

I know this error is infuriating. You ran pip install scikit-learn, saw it succeed, and then Python throws ModuleNotFoundError: No module named 'sklearn'. The twist? You're not alone—this tripped me up the first time too, especially when switching between Python 3.8 and 3.10 on Windows 10.

The root cause is almost always one of three things: you're running a different Python interpreter than the one where scikit-learn was installed, you have a broken or partial install, or your environment (like a Jupyter notebook or Docker container) isn't looking in the right place. Let's fix it, starting with the fastest check.

Quick fix (30 seconds): Verify your environment

Before reinstalling anything, confirm which Python you're actually using. Open a terminal and run:

python --version
pip list | findstr scikit-learn   # Windows
pip list | grep scikit-learn      # macOS/Linux

If scikit-learn shows up but you still get the error, you're likely running a different interpreter than the one pip installed to. Common scenario: you installed via pip3 (or pip inside a virtual env) but run python (which could be Python 2) or a system Python. On macOS, python3 is often separate from python.

The fix: Use the same Python you installed with:

python3 -c "import sklearn; print(sklearn.__version__)"   # macOS/Linux
py -3.10 -m pip install scikit-learn   # Windows with multiple versions

If that works, you're done. If not, move to the moderate fix.

Moderate fix (5 minutes): Reinstall scikit-learn cleanly

Sometimes pip's cache or a partial download leaves you with a broken package. I've seen this happen after a network interruption or an interrupted install. Let's force a clean reinstall:

pip uninstall scikit-learn -y
pip install --no-cache-dir scikit-learn

--no-cache-dir skips the local cache and downloads fresh. On Windows, I've also seen weird issues with long paths, so try using a shorter install directory (e.g., C:\Python310\Scripts instead of AppData\Local\Programs).

After the reinstall, test with:

python -c "import sklearn; print(sklearn.__version__)"

If you still get the error, let's check for a naming mismatch. Old versions of scikit-learn (pre-0.20) used sklearn as the import name but the package was scikit-learn. That shouldn't happen today, but if you're stuck with an ancient version (like from a corporate repo), upgrade:

pip install --upgrade scikit-learn

Advanced fix (15+ minutes): Clean your Python path and environment

If the above didn't work, you've got a deeper conflict. This usually happens when you have multiple Python installations (e.g., anaconda, system Python, and a standalone Python 3.11) or a messy PYTHONPATH. Here's how to untangle it.

Step 1: Find every Python on your system

Run this to see all Python interpreters:

# Windows (in Command Prompt)
where python
where python3

# macOS/Linux
which -a python
which -a python3

If you see more than one, check which one is being used by your IDE or terminal. In VS Code, look at the bottom-left of the status bar—it shows the selected interpreter. In Jupyter, run !which python inside a cell.

Step 2: Reset your virtual environment or conda

If you're using a virtual environment (recommended for any real project), create a fresh one:

# Delete the old one
rm -rf venv

# Create new with Python 3.10 (or your version)
python3.10 -m venv venv
source venv/bin/activate   # On Windows: venv\Scripts\activate
pip install scikit-learn
python -c "import sklearn"

For conda users, I've seen more issues because conda's solver sometimes installs a broken version. Run:

conda remove scikit-learn sklearn
conda clean --all
conda install scikit-learn

Note: conda install sklearn is wrong—it installs a different package (the sklearn library itself is a dummy). Always use scikit-learn.

Step 3: Check for conflicting __init__.py files

This one's rare but I've seen it in Docker images. If you have a file named sklearn.py or a directory named sklearn in your current working directory, Python will import that instead of the real package. Rename it or delete it. Run this to check:

import sys
print([p for p in sys.path if 'sklearn' in p])

If it prints your current directory, you've found the culprit.

Step 4: (Last resort) Repair your Python installation

On Windows, I've had to repair Python once because a Windows Update corrupted the registry. Go to Control Panel > Programs and Features, find Python, click Uninstall, and choose Repair. On macOS, reinstall via Homebrew:

brew reinstall python@3.10

When all else fails

If you're still stuck after these steps, post your pip list output and the exact command you used to run the script. More often than not, people are running python script.py when they meant python3 script.py, or they're in a Docker container that didn't install scikit-learn in the right layer. I've been there—it's almost always a small misalignment. You've got this.

Related Errors in Programming & Dev Tools
SSLError(SSLCertVerificationError) Pip install SSLError: connection broken fix (proxy/SSL) VS Code 1.85 JavaScript IntelliSense Dead: Real Fix 0XC00000FD Fix Stack Overflow 0XC00000FD: Guard Page Error in 2 Steps 0XC00000EB STATUS_UNEXPECTED_MM_MAP_ERROR 0XC00000EB: Real Fix

Was this solution helpful?

EP
Erropedia Team
Tech Support Editors
The Erropedia editorial team researches and documents real-world tech errors from across Windows, Linux, macOS, networking, databases, cloud platforms, and more. Every solution is reviewed for accuracy and updated as software and systems evolve.