[Solved] AttributeError: module ‘cv2.cv2’ has no attribute ‘createLBPHFaceRecognizer’

I am facing some attribute error while running face recognizing the code. My face detects code run perfectly.But while I try to run the face recognizing code it shows some attribute error. I googled and tried to follow all the steps. But still, it shows the same error. Here is my code:

face recognition

enter link description here

and I get the following error:

C:UsersMANAppDataLocalProgramsPythonPython36python.exe C:/Users/MAN/PycharmProjects/facerecognition/Recognise/
Traceback (most recent call last):
  File "C:/Users/MAN/PycharmProjects/facerecognition/Recognise/", line 4, in <module>
    recognizer = cv2.createLBPHFaceRecognizer()
AttributeError: module 'cv2.cv2' has no attribute 'createLBPHFaceRecognizer'

Process finished with exit code 1.

I am using Windows platform. python 3.6 version.Thanks in advance.

Solution #1:

You need to install opencv-contrib

pip install opencv-contrib-python

It should work after that.

Respondent: Željko Krnji?

Solution #2:

if you are using python3.x and opencv==4.1.0 then use following commands
First of all

python -m pip install --user opencv-contrib-python

after that use this in the python script

Respondent: Priyansh gupta

Solution #3:

You might be running Python3 and therefore you are supposed to use pip3 to install the opencv-contrib package :

pip3 install opencv-contrib-python

This worked for me.

Respondent: Raj Krishnan R

Solution #4:

Use the following

recognizer = **cv2.face.LBPHFaceRecognizer_create()**

After you install:

pip install opencv-contrib-python

If using anaconda then in anaconda prompt:

conda install pip


pip install opencv-contrib-python
Respondent: prateek parab

Solution #5:

opencv has changed some functions and moved them to their opencv_contrib repo so you have to call the mentioned method with:

recognizer = cv2.face.createLBPHFaceRecognizer()

Note: You can see this issue about missing docs. Try using help function help(cv2.face.createLBPHFaceRecognizer) for more details.

Respondent: Arpit Solanki

Solution #6:

I got openCV installed smoothly in my mac by:

$ brew install opencv
$ brew link --overwrite --dry-run opencv // to force linking
$ pip3 install opencv-contrib-python

I got it at windows 10 using:

c:> pip3 install opencv-python
c:> pip3 install opencv-contrib-python

Then I got it tested by

$ python3
Python 3.7.3 (default, Mar 27 2019, 09:23:15) 
[Clang 10.0.1 (clang-1001.0.46.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
>>> exit()
Respondent: Hasan A Yousef

Solution #7:

For me changing createLBPHFaceRecognizer() to

recognizer = cv2.face.LBPHFaceRecognizer_create()

fixed the problem

Respondent: skyCode

Solution #8:

python -m pip install --user opencv-contrib-python

After doing this just Restart your system and then if you are on Opencv >= 4.* use :
recognizer = cv2.face.LBPHFaceRecognizer_create()

This should solve 90% of the problem.

Respondent: snehit vaddi

Solution #9:


I tried all of the different things but nothing seems to be working then I just restarted my IDE and it worked like charm.

Still, if it does not work then try restarting your system.

FYI, I am working on the following versions

Respondent: Amit Pathak

Solution #10:

I had a similar problem:

module cv2 has no attribute “cv2.TrackerCSRT_create”

My Python version is 3.8.0 under Windows 10.
The problem was the opencv version installation.

So I fixed this way (cmd prompt with administrator privileges):

  1. Uninstalled opencv-python: pip uninstall opencv-python
  2. Installed only opencv-contrib-python: pip install opencv-contrib-python

Anyway you can read the following guide:

Respondent: Andrea Cassigoli

Solution #11:

For me, I had to have OpenCV (3.4.2), Py-OpenCV (3.4.2), LibOpenCV (3.4.2).

My Python was version 3.5.6 with Anaconda in Windows OS 10.

Respondent: Cloud Cho

Solution #12:

Check your OpenCV version

import cv2

If your are running Python v3.x and OpenCV v4 and above:

pip install opencv-contrib-python

Try running your program again. This should now work.

Respondent: Abhishek Iyengar

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Most Popular

To Top
India and Pakistan’s steroid-soaked rhetoric over Kashmir will come back to haunt them both clenbuterol australia bossier man pleads guilty for leadership role in anabolic steriod distribution conspiracy