---
title: "ModuleNotFoundError: No module named 'cv2' — how to fix it"
description: "Python cannot find OpenCV because the package was installed into a different Python than the one running your script. Here is how to find the right Python and fix it in under five minutes."
url: https://articles.sythra.ai/articles/no-module-named-cv2-fix
slug: no-module-named-cv2-fix
author: "vaibhavkothari"
author_url: https://articles.sythra.ai/writers/vaibhavkothari
date_published: 2026-08-26T08:26:25.097Z
date_modified: 2026-08-29T10:29:25.265Z
topics: ["Python", "Opencv", "Errors"]
reading_time_minutes: 7
publisher: "Sythra"
publisher_url: https://sythra.ai
access: free
language: en
---

# ModuleNotFoundError: No module named 'cv2' — how to fix it

> Python cannot find OpenCV because the package was installed into a different Python than the one running your script. Here is how to find the right Python and fix it in under five minutes.

Source: https://articles.sythra.ai/articles/no-module-named-cv2-fix · Author: vaibhavkothari · Published: 2026-08-26 · Reading time: 7 min · Topics: Python, Opencv, Errors

`ModuleNotFoundError: No module named 'cv2'` almost never means OpenCV is broken. It means the Python running your script is **not the Python you installed OpenCV into**.

Most computers have several Pythons: the system one, one from the Microsoft Store, one from Anaconda, and one inside every virtual environment you ever made. `pip install opencv-python` puts the package in exactly one of them. If your editor runs a different one, Python looks around, finds no `cv2`, and raises this error.

This guide shows you how to find which Python is actually running, install into *that* one, and stop the error from coming back.

## What you need

- Python 3.8 or newer
- A terminal (Command Prompt / PowerShell on Windows, Terminal on macOS and Linux)
- Five minutes

## Step 1 — Ask Python which Python it is

Do not guess. Make Python tell you. Create a file called `whoami.py`:

```python
import sys

print("Executable:", sys.executable)
print("Version:", sys.version)
```

Run it **the same way you run your real script** — same editor, same button, same terminal:

```bash
python whoami.py
```

You get something like:

```text
Executable: C:\Users\You\AppData\Local\Programs\Python\Python312\python.exe
Version: 3.12.3
```

That path is the only Python that matters. Copy it somewhere — you will use it in the next step.

> If the path contains `envs\something` or `.venv`, you are inside a virtual environment. That is fine, and it is usually the real cause: the environment is new and empty.

## Step 2 — Install OpenCV into that exact Python

Now install using that interpreter directly instead of the bare `pip` command. This is the single most reliable fix, because it removes all guessing:

```bash
python -m pip install opencv-python
```

`python -m pip` means "use the pip that belongs to *this* Python". It is safer than plain `pip`, which may belong to a completely different install.

On macOS and Linux, if `python` points at an old Python 2, use:

```bash
python3 -m pip install opencv-python
```

If you copied a full path in Step 1, you can be even more explicit:

```bash
"C:\Users\You\AppData\Local\Programs\Python\Python312\python.exe" -m pip install opencv-python
```

## Step 3 — Verify the install

Check it from the command line so no editor setting can lie to you:

```bash
python -c "import cv2; print(cv2.__version__)"
```

A version number like `4.10.0` means OpenCV is installed and importable. If you still get the error here, the install went to another Python — go back to Step 1 and read the path again carefully.

You can also confirm where the package landed:

```bash
python -m pip show opencv-python
```

The `Location:` line should sit inside the same folder tree as the executable path from Step 1.

## Step 4 — Fix your editor if the terminal works but the editor does not

This is the most common leftover problem: `python -c "import cv2"` works in the terminal, but VS Code or Jupyter still shows the error. The editor is running a different interpreter.

**VS Code**

1. Press `Ctrl+Shift+P` (`Cmd+Shift+P` on macOS)
2. Type **Python: Select Interpreter**
3. Pick the path you saw in Step 1
4. Close and reopen the terminal panel inside VS Code

**Jupyter Notebook or JupyterLab**

Run this *inside a notebook cell* — it installs into the kernel the notebook is actually using:

```python
import sys
!{sys.executable} -m pip install opencv-python
```

Then restart the kernel. This trick works for any package, not just OpenCV.

**Google Colab**

OpenCV is already installed. If you still see the error, you almost certainly typed `import cv` or `import opencv` instead of `import cv2`.

## Step 5 — Pick the right OpenCV package

There are several OpenCV packages on PyPI and installing two of them at once causes strange errors. Install **one**:

| Package | Use it when |
|---|---|
| `opencv-python` | Normal desktop use — webcam, windows, image files. Start here. |
| `opencv-contrib-python` | You need extra algorithms (SIFT, tracking, ArUco markers) |
| `opencv-python-headless` | Servers, Docker, CI — no GUI windows available |

If you already installed more than one, clean up and reinstall a single package:

```bash
python -m pip uninstall -y opencv-python opencv-contrib-python opencv-python-headless
python -m pip install opencv-python
```

## Common mistakes (and fixes)

| What you see | What it means | Fix |
|---|---|---|
| `No module named 'cv2'` after a successful install | Installed into a different Python | Use `python -m pip install opencv-python` |
| `No module named 'opencv'` | Wrong import name | The import is always `import cv2` |
| `pip is not recognized` | pip is not on your PATH | See our [pip is not recognized fix](https://articles.sythra.ai/articles/pip-not-recognized-windows-fix) |
| Works in terminal, fails in VS Code | Editor uses another interpreter | Python: Select Interpreter |
| Works in VS Code, fails in Jupyter | Notebook kernel is a different Python | `!{sys.executable} -m pip install opencv-python` |
| `ImportError: DLL load failed` on Windows | Missing Visual C++ runtime | Install the Microsoft Visual C++ Redistributable, then reinstall |

## Make it never happen again

Use one virtual environment per project. It sounds like extra work; it removes this entire class of bug:

```bash
python -m venv .venv
```

Activate it:

```bash
# Windows PowerShell
.venv\Scripts\Activate.ps1

# macOS / Linux
source .venv/bin/activate
```

Then install as usual. Everything you install now belongs to this project only, and `sys.executable` will point inside `.venv`. If you are unsure which environment tool to use, we compared them in [venv vs conda vs uv](https://articles.sythra.ai/articles/venv-vs-conda-vs-uv).

## What you learned

- The error is about **which Python**, not about OpenCV
- `sys.executable` tells you the truth; guessing does not
- `python -m pip install` always installs into the running Python
- Editors and notebooks have their own interpreter setting
- One virtual environment per project prevents repeats

```remember
# Remember this
`import sys; print(sys.executable)` -> which Python is actually running
`python -m pip install opencv-python` -> installs into *that* Python
---
The error is about **which Python**, not about OpenCV.
One virtual environment per project stops it coming back.
```


## FAQ

### Why does Python say No module named 'cv2' when OpenCV is installed?

Because the Python running your script is not the Python that has OpenCV. Print `sys.executable` to see which interpreter is running, then install with `python -m pip install opencv-python` using that same interpreter.

### What is the correct pip command to install OpenCV?

Use `python -m pip install opencv-python`. The `python -m` prefix guarantees the package goes into the Python you are currently running, which plain `pip` cannot promise.

### Should I install opencv-python or opencv-contrib-python?

Install `opencv-python` for normal webcam and image work. Choose `opencv-contrib-python` only if you need extra algorithms such as SIFT or ArUco markers, and never install both at the same time.

### How do I fix No module named cv2 in Jupyter Notebook?

Run `import sys` then `!{sys.executable} -m pip install opencv-python` inside a notebook cell and restart the kernel. This installs into the exact kernel the notebook uses instead of some other Python on your machine.

### Why does import cv2 fail with DLL load failed on Windows?

The OpenCV binary needs the Microsoft Visual C++ Redistributable. Install it, then run `python -m pip install --force-reinstall opencv-python`.

## Next reading on Sythra Articles

- [Build a virtual mouse with OpenCV and MediaPipe](https://articles.sythra.ai/articles/virtual-mouse-opencv-mediapipe) — the project this fix usually unblocks
- [Your first Python program](https://articles.sythra.ai/articles/first-python-hello) — if you are brand new
- [Real-time face detection in Python](https://articles.sythra.ai/articles/face-detection-python-mediapipe-vs-haar)

## Glossary (terms defined in this article)
- **virtual environment** (basic) — A private folder holding its own copy of Python and its own packages
- **interpreter** (basic) — The specific python.exe your editor uses to run code
