problem in Installing (python Library) face_recognition on windows 10/11

Question:

I am using python 3.9.9
pip 21.3.1

I am trying to install face_recognition

so I installed CMake
then when I tried to install dlib using command pip install dlib I got the following

Collecting dlib
  Using cached dlib-19.22.1.tar.gz (7.4 MB)
  Prep

    aring metadata (setup.py) ... done
    Building wheels for collected packag

es: dlib
  Building wheel for dlib (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: 'C:UsersaenasAppDataLocalMicrosoftWindowsAppsPythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\aenas\AppData\Local\Temp\pip-install-78dld3fg\dlib_098968d181654cc09e283aff4801a4b1\setup.py'"'"'; __file__='"'"'C:\Users\aenas\AppData\Local\Temp\pip-install-78dld3fg\dlib_098968d181654cc09e283aff4801a4b1\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'rn'"'"', '"'"'n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d 'C:UsersaenasAppDataLocalTemppip-wheel-hjnpx8xk'
       cwd: C:UsersaenasAppDataLocalTemppip-install-78dld3fgdlib_098968d181654cc09e283aff4801a4b1
  Complete output (8 lines):
  running bdist_wheel
  running build
  running build_py
  package init file 'toolspythondlib__init__.py' not found (or not a regular file)
  running build_ext

  ERROR: CMake must be installed to build dlib

  ----------------------------------------
  ERROR: Failed building wheel for dlib
  Running setup.py clean for dlib
Failed to build dlib
Installing collected packages: dlib
    Running setup.py install for dlib ... error
    ERROR: Command errored out with exit status 1:
     command: 'C:UsersaenasAppDataLocalMicrosoftWindowsAppsPythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\aenas\AppData\Local\Temp\pip-install-78dld3fg\dlib_098968d181654cc09e283aff4801a4b1\setup.py'"'"'; __file__='"'"'C:\Users\aenas\AppData\Local\Temp\pip-install-78dld3fg\dlib_098968d181654cc09e283aff4801a4b1\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'rn'"'"', '"'"'n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:UsersaenasAppDataLocalTemppip-record-zbjc8ulwinstall-record.txt' --single-version-externally-managed --user --prefix= --compile --install-headers 'C:UsersaenasAppDataLocalPackagesPythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0LocalCachelocal-packagesPython39Includedlib'
         cwd: C:UsersaenasAppDataLocalTemppip-install-78dld3fgdlib_098968d181654cc09e283aff4801a4b1
    Complete output (8 lines):
    running install
    running build
    running build_py
    package init file 'toolspythondlib__init__.py' not found (or not a regular file)
    running build_ext

    ERROR: CMake must be installed to build dlib

    ----------------------------------------
ERROR: Command errored out with exit status 1: 'C:UsersaenasAppDataLocalMicrosoftWindowsAppsPythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\aenas\AppData\Local\Temp\pip-install-78dld3fg\dlib_098968d181654cc09e283aff4801a4b1\setup.py'"'"'; __file__='"'"'C:\Users\aenas\AppData\Local\Temp\pip-install-78dld3fg\dlib_098968d181654cc09e283aff4801a4b1\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'rn'"'"', '"'"'n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:UsersaenasAppDataLocalTemppip-record-zbjc8ulwinstall-record.txt' --single-version-externally-managed --user --prefix= --compile --install-headers 'C:UsersaenasAppDataLocalPackagesPythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0LocalCachelocal-packagesPython39Includedlib' Check the logs for full command output.**

and when I tried to install face_recognition using command pip install face_recognition
I got the following:

Collecting face_recognition
  Using cached face_recognition-1.3.0-py2.py3-none-any.whl (15 kB)
Requirement already satisfied: face-recognition-models>=0.3.0 in c:usersaenasappdatalocalpackagespythonsoftwarefoundation.python.3.9_qbz5n2kfra8p0localcachelocal-packagespython39site-packages (from face_recognition) (0.3.0)
Collecting dlib>=19.7
  Using cached dlib-19.22.1.tar.gz (7.4 MB)
  Preparing metadata (setup.py) ... done
Collecting Click>=6.0
  Using cached click-8.0.3-py3-none-any.whl (97 kB)
Requirement already satisfied: numpy in c:usersaenasappdatalocalpackagespythonsoftwarefoundation.python.3.9_qbz5n2kfra8p0localcachelocal-packagespython39site-packages (from face_recognition) (1.21.4)
Requirement already satisfied: Pillow in c:usersaenasappdatalocalpackagespythonsoftwarefoundation.python.3.9_qbz5n2kfra8p0localcachelocal-packagespython39site-packages (from face_recognition) (8.4.0)
Requirement already satisfied: colorama in c:usersaenasappdatalocalpackagespythonsoftwarefoundation.python.3.9_qbz5n2kfra8p0localcachelocal-packagespython39site-packages (from Click>=6.0->face_recognition) (0.4.4)
Building wheels for collected packages: dlib
  Building wheel for dlib (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: 'C:UsersaenasAppDataLocalMicrosoftWindowsAppsPythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\aenas\AppData\Local\Temp\pip-install-cy9bzkon\dlib_8e45a10b6067402ab676a29d5bd742c8\setup.py'"'"'; __file__='"'"'C:\Users\aenas\AppData\Local\Temp\pip-install-cy9bzkon\dlib_8e45a10b6067402ab676a29d5bd742c8\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'rn'"'"', '"'"'n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d 'C:UsersaenasAppDataLocalTemppip-wheel-elyfs9nv'
       cwd: C:UsersaenasAppDataLocalTemppip-install-cy9bzkondlib_8e45a10b6067402ab676a29d5bd742c8
  Complete output (8 lines):
  running bdist_wheel
  running build
  running build_py
  package init file 'toolspythondlib__init__.py' not found (or not a regular file)
  running build_ext

  ERROR: CMake must be installed to build dlib

  ----------------------------------------
  ERROR: Failed building wheel for dlib
  Running setup.py clean for dlib
Failed to build dlib
Installing collected packages: dlib, Click, face-recognition
    Running setup.py install for dlib ... error
    ERROR: Command errored out with exit status 1:
     command: 'C:UsersaenasAppDataLocalMicrosoftWindowsAppsPythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\aenas\AppData\Local\Temp\pip-install-cy9bzkon\dlib_8e45a10b6067402ab676a29d5bd742c8\setup.py'"'"'; __file__='"'"'C:\Users\aenas\AppData\Local\Temp\pip-install-cy9bzkon\dlib_8e45a10b6067402ab676a29d5bd742c8\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'rn'"'"', '"'"'n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:UsersaenasAppDataLocalTemppip-record-oojov4ijinstall-record.txt' --single-version-externally-managed --user --prefix= --compile --install-headers 'C:UsersaenasAppDataLocalPackagesPythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0LocalCachelocal-packagesPython39Includedlib'
         cwd: C:UsersaenasAppDataLocalTemppip-install-cy9bzkondlib_8e45a10b6067402ab676a29d5bd742c8
    Complete output (8 lines):
    running install
    running build
    running build_py
    package init file 'toolspythondlib__init__.py' not found (or not a regular file)
    running build_ext

    ERROR: CMake must be installed to build dlib

    ----------------------------------------
ERROR: Command errored out with exit status 1: 'C:UsersaenasAppDataLocalMicrosoftWindowsAppsPythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\aenas\AppData\Local\Temp\pip-install-cy9bzkon\dlib_8e45a10b6067402ab676a29d5bd742c8\setup.py'"'"'; __file__='"'"'C:\Users\aenas\AppData\Local\Temp\pip-install-cy9bzkon\dlib_8e45a10b6067402ab676a29d5bd742c8\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'rn'"'"', '"'"'n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:UsersaenasAppDataLocalTemppip-record-oojov4ijinstall-record.txt' --single-version-externally-managed --user --prefix= --compile --install-headers 'C:UsersaenasAppDataLocalPackagesPythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0LocalCachelocal-packagesPython39Includedlib' Check the logs for full command output.

Though I have tried many solution but none of them solved my problem

Asked By: Abdelrahman Nassar

||

Answers:

Fortunately, I solved the problem. These are the steps to download face_recognition Library:

1- install python:

in the command prompt write python and click Enter, this will open
Microsoft store for you, "click download" or "install" to download and
install python. "to check if it is downloaded or not type python in the
command prompt

2- install pip if you do not have it:

go to: https://pypi.org/project/pip-download/
click download files. Now open the downloaded file, then click right click
with the mouse and choose "open in windows terminal". now type the command
python get-pip.py. now your pip should be installed, type pip in the
terminal to check if it is installed

3-Install Visual Studio tools For C++

go to: https://visualstudio.microsoft.com/ and download the community
version of VS. after downloading install it and choose the following
options in the installation page:
image1 image2

and choose install

4- installing cmake

Enter the command pip install cmake and wait fo it to be installed.

5- Add cmake to the Path variable

follow the instructions in the following link to know how to add
something to your Path variable:
https://helpdeskgeek.com/windows-10/add-windows-path-environment-variable/

6- Install dlib

write the following command in the command prompt: pip install dlib

7- install face_recognition

write the following command in the command prompt: pip install face_recognition

8- start your project in PyCharm

click File click Sittings in the search type "interpreter" choose
"python interpreter" choose "show all" click the "+" sign choose
system Interpreter choose the interpreter that its path starts with
the "users" directory

That is the solution I used to fix my problem

Answered By: Abdelrahman Nassar

After doing all the steps described, I still get the following error:
Any help at all will be greatly appreciated!

Collecting dlib 
  Using cached dlib-19.24.0.tar.gz (3.2 MB) 
  Preparing metadata (setup.py) ... done 

Installing collected packages: dlib
  DEPRECATION: dlib is being installed using the legacy 'setup.py install' method, because it does not have a 'pyproject.toml' and the 'wheel' package is not installed. pip 23.1 will enforce this behaviour change. A possible replacement is to enable the '--use-pep517' option. Discussion can be found at https://github.com/pypa/pip/issues/8559
  Running setup.py install for dlib ... error
  error: subprocess-exited-with-error

  × Running setup.py install for dlib did not run successfully.
  │ exit code: 1
  ╰─> [9 lines of output]
      running install
      C:Program FilesWindowsAppsPythonSoftwareFoundation.Python.3.10_3.10.2288.0_x64__qbz5n2kfra8p0libsite-packagessetuptoolscommandinstall.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
        warnings.warn(
      running build
      running build_py
      running build_ext

      ERROR: CMake must be installed to build dlib

      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure

× Encountered error while trying to install package.
╰─> dlib

note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.
Answered By: Spad