Last modified: Jun 20, 2025 By Alexander Williams

How to Uninstall OpenCV (cv2) in Python

OpenCV (cv2) is a popular library for computer vision tasks. Sometimes, you may need to uninstall it. This guide will help you remove OpenCV cleanly.

Why Uninstall OpenCV?

You might need to uninstall OpenCV for several reasons. Maybe you want to install a different version. Or perhaps you're troubleshooting issues.

Whatever the reason, proper uninstallation is important. It prevents conflicts with other packages.

Check OpenCV Installation

First, verify if OpenCV is installed. Use the pip show command in your terminal.


pip show opencv-python

If installed, this will display package details. If not, you'll see a "not found" message.

Uninstall OpenCV Using Pip

The easiest way to remove OpenCV is with pip. Run this command in your terminal.


pip uninstall opencv-python

You'll see a confirmation prompt. Type 'y' and press Enter to proceed.

Uninstall OpenCV-headless

If you installed the headless version, uninstall it separately.


pip uninstall opencv-python-headless

This ensures all OpenCV components are removed.

Verify Uninstallation

After uninstalling, verify OpenCV is gone. Try importing it in Python.


import cv2
print(cv2.__version__)

You should get an ImportError. This confirms successful removal.

Clean Up Residual Files

Sometimes, pip leaves behind files. Check these locations and delete any OpenCV remnants.

On Windows:


C:\PythonXX\Lib\site-packages\cv2

On Linux/Mac:


/usr/local/lib/pythonX.X/site-packages/cv2

Reinstall OpenCV (Optional)

If you need a different version, install it after removal.


pip install opencv-python==4.5.5.64

Replace the version number as needed.

Troubleshooting

If you encounter issues, try these solutions.

Permission Errors: Use sudo on Linux/Mac or run as admin on Windows.

Multiple Python Versions: Specify the correct pip version (e.g., pip3).

Virtual Environments: Activate your environment first.

Need to remove other Python packages? Check these guides:

How to Uninstall TensorFlow in Python

How to Uninstall scikit-learn in Python

How to Uninstall PyTorch in Python

Conclusion

Uninstalling OpenCV is straightforward with pip. Always verify removal and clean up residual files.

This ensures a clean environment for reinstalling or using other computer vision libraries.