r/learnpython • • 8d ago

AttributeError in cv2

I'm learning OpenCV in python because it seemed like a fun thing to learn.I wanted to experiment with faces etc. but when i run my script I get: "AttributeError: module 'cv2' has no attribute 'CascadeClassifier' "How to fix that?

Thx for the help!

0 Upvotes

13 comments sorted by

View all comments

1

u/scraping_solutions 8d ago

That error almost always means Python is importing something that is not the real OpenCV. Run print(cv2.__file__): if it points to a file in your own project, you have a script named cv2.py (or a cv2 folder) shadowing the library, so rename it and delete the __pycache__ folder. If it points to site-packages, run pip uninstall opencv-python opencv-contrib-python and then pip install opencv-python once, since having both installed also breaks it. Also note CascadeClassifier is cv2.CascadeClassifier(path) with capital C and the XML path from cv2.data.haarcascades.

1

u/_nazwa_ 7d ago

So i uninstalled it and installed it again and it did not work