[Solved] OpenCV Error: AttributeError: module ‘cv2‘ has no attribute ‘data‘

Opencv error: attributeerror: module ‘CV2’ has no attribute ‘data’
the following error will appear when running the face detection code:

face_detector = cv.CascadeClassifier(cv.data.haarcascades + "haarcascade_frontalface_alt2.xml")
eye_detector = cv.CascadeClassifier(cv.data.haarcascades + "haarcascade_eye.xml")
smile_detector = cv.CascadeClassifier(cv.data.haarcascades + "haarcascade_smile.xml")


AttributeError: module 'cv2' has no attribute 'data'

Solution: uninstall your existing opencv Python and install my version of OpenCV

1. Open Anaconda prompt and enter

pip uninstall opencv-python

2. Re input

pip install opencv-python -i http://mirrors.aliyun.com/pypi/simple --trusted-host mirrors.aliyun.com

Note: when uninstalling opencv, select y, and don’t worry about red explosion

Read More: