Install opencv-python via pip
4.xTo install pre-built CPU-only OpenCV packages, use pip.
Important Prerequisites:
- Remove existing manual installations: If you have a
cv2module manually installed in your Pythonsite-packages(not viapip), remove it first to avoid conflicts. - Upgrade pip: Ensure your
pipversion is at least 19.3. Usepip install --upgrade pip. - Select ONLY ONE package: All packages share the same
cv2namespace. Installing multiple packages in the same environment will cause conflicts. Uninstall all existing versions before installing a new one.
Package Options:
| Environment Type | Package Name | Description |
| :--- | :--- | : |
| Standard Desktop (Windows, macOS, Linux) | opencv-python | Main modules only |
| | opencv-contrib-python | Main modules + contrib/extra modules |
| Server/Headless (Docker, Cloud, no GUI) | opencv-python-headless | Main modules, no GUI dependencies |
| | opencv-contrib-python-headless | Main modules + contrib/extra, no GUI dependencies |
Note: Use headless packages if you do not use cv2.imshow or if you use another library (like PyQt) for your GUI to keep Docker images small and avoid X11 dependencies.