Solving AttributeError: module ‘cv2.cv2’ has no attribute ‘createLBPHFaceRecognizer’

AttributeError: module ‘cv2.cv2’ has no attribute ‘createLBPHFaceRecognizer’ is a common error which occurs when opencv has a faulty installation or opencv dependencies are not installed.

In this post we will try to solve your error and see why it occurs in the first place, we will present multiple solutions so you can find the one which suits your case.

Exploring the Error : AttributeError: module ‘cv2.cv2’ has no attribute ‘createLBPHFaceRecognizer’

This is a common error which occurs when opencv has a faulty installation or opencv dependencies are not installed.

First of all, let us check out how the message of the error looks like.

Bellow I will present multiple solutions some have worked for me and others have worked for other developers.

Solution 1 : install opencv-contrib-python

The solution is simple, start by installing opencv-contrib-python. You can do that using the command bellow.

                                                                       #
sudo pip install opencv-contrib-python
                                                                       #

If that did not work You can also try the following command.

                                                                       #
sudo pip3 install opencv-contrib-python==4.5.0.4
                                                                       #

You can choose a version here https://www.piwheels.org/project/opencv-contrib-python/#install

You can now install these libraries using the following command.

                                                                       #
sudo apt install libaec0 libaom0 libatk-bridge2.0-0 libdrm2 libepoxy0 libfontconfig1 libgdk-pixbuf2.0-0 libgfortran5 libgme0 libgraphite2-3 libgsm1 libgtk-3-0 libvorbis0a libvorbisenc2 libvorbisfile3 libvpx5 libwavpack1 libxcursor1 libxdamage1 libxfixes3 libxi6 libxinerama1 libxkbcommon0 libxrandr2 libxrender1 libxvidcore4 libzvbi0 libsnappy1v5 libsoxr0 libspeex1 libssh-gcrypt-4 libswresample3 libswscale5 libsz2 libthai0 libtheora0 libtiff5 libtwolame0 libva-drm2 libva-x11-2 libva2 libvdpau1 libharfbuzz0b libhdf5-103 libilmbase23 libjbig0 libmp3lame0 libmpg123-0 libogg0 libopenexr23 libopenjp2-7 libopenmpt0 libopus0 libpango-1.0-0 libpangocairo-1.0-0 libpangoft2-1.0-0 libpixman-1-0 librsvg2-2 libshine3 libatk1.0-0 libatlas3-base libatspi2.0-0 libavcodec58 libavformat58 libavutil56 libbluray2 libcairo-gobject2 libcairo2 libchromaprint1 libcodec2-0.8.1 libcroco3 libdatrie1 libwayland-client0 libwayland-cursor0 libwayland-egl1 libwebp6 libwebpmux3 libx264-155 libx265-165 libxcb-render0 libxcb-shm0 libxcomposite1
                                                                       #

For most people, the error should be gone by now. If it does not please follow the solution bellow.

Solution 2 : uninstall opencv-python first

The second solution is as simple as the previous solution.

First, you should start by removing opencv-python from your system.

You can do that by using the command bellow.

                                                                       #
pip uninstall opencv-python
                                                                       #

Now, you should install opencv-contrib-python by using the command bellow.

                                                                       #
pip install opencv-contrib-python
                                                                       #

I hope this guide solved your problem, thank you for reading this blog post.

Summing-up

This is the end of our guide, I hope you found at least one solution useful, we try to provide solutions for both Linux and windows users, If you did not solve the issue, I hope you find it online, do not give up, errors are normal in Python, Cheers.

If you want to learn more about Python, please check out the Python Documentation : https://docs.python.org/3/