The package is called opencv-python, but you import it as cv2. Install it with the same Python that runs your script.
What the message means
Several Pythons can live on one computer. A package installed for one is not visible to the other.
Fix it in this order
- Run python -m pip install opencv-python using the exact Python you use to run the script.
- Activate your virtual environment first if you use one.
- Check which Python runs with python –version and where pip installs.
- Select the same interpreter in your editor.
- Do not install several OpenCV packages at once, since they conflict.
Why it happens
The name you install and the name you import can differ. The package is installed as opencv-python but imported as cv2, so pip install cv2 will not find it.
A computer can have several Python installations, and each has its own packages. An install made for one is not visible to another, so the error often means pip and your script use different Pythons. Running python -m pip with the same python that runs the script keeps them together.
If you see this, do this
| You see | Do this |
|---|---|
| Installed but still missing | Different Python. |
| Import crashes after installing two packages | Remove all and install one. |
Related
cannot open camera, camera calibration.
Last reviewed: November 2026. These are the usual causes and the order that finds them fastest. Test on your own board; clones and cables differ.
Why this happens
Python finds modules by searching the folders listed for the interpreter that runs your script. Each installation has its own folder of packages. pip is also tied to one interpreter, so running pip for one Python and the script with another leaves the package invisible, even though the install said success.
The second trap is naming. The package on the index is opencv-python, and it installs a module called cv2. Typing pip install cv2 searches for something else. Variants such as opencv-python-headless and opencv-contrib-python provide the same cv2 module and should not be mixed.
How to confirm the cause
- Run python -c “import sys; print(sys.executable)” in the same terminal and with the same command you use for the script. That is the interpreter that matters.
- Run python -m pip –version. The path it prints should be inside the same Python installation.
- Run python -m pip show opencv-python. If it says the package is not found, it was installed elsewhere.
- Check your editor’s selected interpreter. The editor may run a different Python from the terminal.
- Look in your project folder for a file called cv2.py or opencv.py. It would be imported instead of the real package.
Worked example
On Windows, run these four commands one after another in the terminal you use for your project.
python -c "import sys; print(sys.executable)"
python -m pip --version
python -m pip install opencv-python
python -c "import cv2; print(cv2.__version__)"
# a version number printed means the import now worksCommon mistakes
- Typing pip install cv2.
- Using pip for one Python and python3 for another.
- Naming your own script cv2.py, which hides the real module.
- Installing opencv-python and opencv-contrib-python together.
- Installing into a virtual environment and then running the script outside it.
If this did not fix it
- A Python version for which no ready-made package exists yet. Try an earlier, widely used Python version.
- On a Raspberry Pi or Linux system that protects its system Python, install inside a virtual environment.
- An ImportError that mentions a DLL or shared library is a different fault: a missing system library or a mixed install.