OpenCV Python in VS Code
- 1
Install the Python extension
Open VS Code → Extensions (Ctrl+Shift+X) → search Python → install the Microsoft Python extension.
- 2
Select the correct Python interpreter
Press Ctrl+Shift+P → type Python: Select Interpreter → choose the Python where OpenCV is installed. You should see
opencv-pythonin the list if it is installed there. - 3
Install OpenCV in that environment
C:\> pip install opencv-python# Or use the venv from the workspace:C:\> python -m venv .venvC:\> .venv\Scripts\activate(.venv) C:\> pip install opencv-python - 4
Verify IntelliSense works
Create a new file
test.py, typeimport cv2thencv2.— you should see autocomplete suggestions. If not, reload VS Code window: Ctrl+Shift+P → Developer: Reload Window.
OpenCV C++ IntelliSense in VS Code
For C++ projects, configure the c_cpp_properties.json file to point at the OpenCV include directory:
Build and run C++ from VS Code
VS Code questions
import cv2 works in terminal but fails in VS Code
cv2 shows as unresolved import in VS Code
pip install opencv-stubs. VS Code Pylance will use these for autocomplete. Alternatively select the correct interpreter and the issue usually resolves itself.C++ IntelliSense shows errors but code compiles fine
c_cpp_properties.json include path is not set. Make sure the OpenCV include directory is in includePath. Also check intelliSenseMode is windows-msvc-x64 for Visual Studio compiler.