Error messages
Common import cv2 errors on Windows
ModuleNotFoundError: No module named 'cv2'
OpenCV not installed in the active Python environment
pip install opencv-pythonImportError: DLL load failed while importing cv2
Missing Visual C++ Redistributable or wrong Python bitness
Install vc_redist.x64.exe then pip install opencv-python --force-reinstallImportError: cannot import name 'cv2' from partially initialized module
Local file named cv2.py conflicts with the package
Delete or rename any file called cv2.py in your projectImportError: numpy.core.multiarray failed to import
NumPy version incompatible with installed OpenCV
pip install --upgrade numpyFix 1 — most common
OpenCV not installed in your Python environment
# Check if OpenCV is installed:
C:\> pip show opencv-python
WARNING: Package(s) not found: opencv-python
# Install it:
C:\> pip install opencv-python
Successfully installed opencv-python-4.12.0.86
# Verify:
C:\> python -c "import cv2; print(cv2.__version__)"
4.12.0
Fix 2
Wrong Python environment
Windows often has multiple Python installations. OpenCV may be installed in one Python but you are running another. Diagnose:
# Check which Python is active:
C:\> where python
C:\Users\name\AppData\Local\Programs\Python\Python311\python.exe
C:\Python39\python.exe
# First result is the one used by default
# Install to the correct Python explicitly:
C:\> C:\Users\name\AppData\Local\Programs\Python\Python311\python.exe -m pip install opencv-python
Use
python -m pip install opencv-python instead of just pip install to ensure you install to the Python you are actually running.Fix 3
Local file named cv2.py
If you have a file called cv2.py in your project directory, Python imports it instead of the OpenCV package. Check:
# List Python files in current directory:
C:\> dir *.py
# Look for cv2.py or any file that might shadow the package
Rename or delete any cv2.py file in your project directory. Also check for cv2 folders.
Fix 4
NumPy compatibility issue
# Check NumPy version:
C:\> python -c "import numpy; print(numpy.__version__)"
# Update NumPy:
C:\> pip install --upgrade numpy
# Or pin to a compatible version:
C:\> pip install "numpy<2.0"
OpenCV 4.9 and older may not be compatible with NumPy 2.0. If you see NumPy errors, downgrade:
pip install "numpy<2.0"FAQ
Import error questions
Works in cmd.exe but not in VS Code / PyCharm
Your IDE is using a different Python interpreter. In VS Code: Ctrl+Shift+P → "Python: Select Interpreter" → choose the Python where OpenCV is installed. In PyCharm: File → Settings → Project → Python Interpreter.
pip install succeeds but import still fails
Run
python -m pip install opencv-python (with the explicit python -m) to ensure pip installs to the Python you are running. Then test with the same Python: python -c "import cv2".import cv2 works in script but fails in Jupyter Notebook
Jupyter uses a different kernel Python. In the notebook run:
import sys; print(sys.executable) to see which Python. Then install OpenCV in that Python: !pip install opencv-python from a notebook cell.