Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows Installation Guide #175

Closed
masoudr opened this issue Sep 14, 2017 · 274 comments
Closed

Windows Installation Guide #175

masoudr opened this issue Sep 14, 2017 · 274 comments

Comments

@masoudr
Copy link

masoudr commented Sep 14, 2017

Hi,
I've successfully installed and tested this tool on my Windows 10 machine, and I'm writing a simple procedure to install it. It may be useful for some people to try to use this tool on a Windows machine.

IMPORTANT: Actually, this project has been done for Linux systems, especially dlib. In my tests, the performance of this tool in Windows 10 was about a quarter compared to Ubuntu, built with the same specs. But I haven't seen any difference between these two in other subjects.

Read First:
The new version of dlib doesn't need Boost anymore, so you can skip it. Remember that you still need to meet the following requirements.
Requirments:
(I've used this tutorial with these tools installed on Windows 10, but the newer versions may work too.)

  1. Microsoft Visual Studio 2015 (or newer) with C/C++ Compiler installed. (Visual C++ 2015 Build Tools didn't work for me, and I got into problems in compiling dlib)
  2. Of course Python3 (I used Python3.5 x64 but the other versions may work too)
  3. CMake for windows and add it to your system environment variables.
  4. (ONLY FOR older versions of dlib) Boost library version 1.63 or newer. Also, you can use precompiled binaries for specific MSVC you have, but I don't suggest. (I've included the compiling procedure of Boost in this tutorial)

Installation:
Easy installation:
Just install dlib and face_recognition (not always on the newest version):
pip install dlib and then pip install face_recognition.

Manual installation:

  1. Download and install scipy and numpy+mkl (must be mkl version) packages from this link (all credits goes to Christoph Gohlke). Remember to grab the correct version based on your current Python version.
  2. Download Boost library source code or binary release for your current MSVC from this link.
  3. If you downloaded the binary version skip to step 4 else, follow these steps to compile and build Boost by yourself:
    3-1. Extract the Boost source files into C:\local\boost_1_XX_X (X means the current version of Boost you have)
    3-2. Create a system variable with these parameters:
    Name: VS140COMNTOOLS
    Value: C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\ (or any path where you have installed MSVC)
    3-3. Open Developer Command Prompt for Visual Studio and go to the current directory of Boost extracted and try these commands to compile Boost:
    bootstrap
    b2 -a --with-python address-model=64 toolset=msvc runtime-link=static
    3-4. If you successfully compile Boost, it should create compiled files in stage directory.
  4. (If you have already compiled Boost skip this step) If you already download the binary release, extract the contents to C:\local\boost_1_XX_X
  5. Grab the latest version of dlib from this repo and extract it.
  6. Go to dlib directory and open cmd and follow these commands to build dlib: (remember to replace XX with the current version of Boost you have)
    set BOOST_ROOT=C:\local\boost_X_XX_X
    set BOOST_LIBRARYDIR=C:\local\boost_X_XX_X\stage\lib
    python setup.py install --yes USE_AVX_INSTRUCTIONS or python setup.py install --yes USE_AVX_INSTRUCTIONS --yes DLIB_USE_CUDA
  7. Now, you can use import dlib without any problem in your python script.
  8. You can also check the current version of dlib with pip show dlib.
  9. Now, install face_recognition with pip install face_recognition.
  10. Enjoy!

Finally, I need to say thanks to @ageitgey and @davisking for their awesome work.

@TheDogeOfTheInternet
Copy link

You don't need to manually install dlib. I was able to install it with pip (through the pip install face_recognition command) after I had Boost and CMake installed.

Which leads me to my second point; your tutorial does not mention CMake at all. I have no idea what CMake actually does, so it may not be required, but if it does have something to do with simplifying the install process, you should add it to your tutorial.

@masoudr
Copy link
Author

masoudr commented Sep 14, 2017

@TheDogeOfTheInternet yes you are right the CMake is a must and I forgot to add it but it is just used to compile dlib and Boost. I've edited my post and add it thanks.
And for your first question yes you can use pip to install it but the latest versions are always on his Github repository and website so you need to compile it by yourself. Also, you can configure your compilation.

@ageitgey
Copy link
Owner

Thanks @masoudr! I'll link it from the README.

@ageitgey
Copy link
Owner

Done! https://github.com/ageitgey/face_recognition/blob/master/README.md#installation

Thanks again!

@PBShortStop
Copy link

hello @masoudr, i want to know CMake install procedure. Thanks.

@masoudr
Copy link
Author

masoudr commented Sep 19, 2017

@PBShortStop Installation of CMake in windows is very simple just grab the installation file (*.msi) from this link and install it. Remember to check the "Add CMake to system path" during the installation. Then you can simply use cmake --version in command prompt.

@BachDoXuan
Copy link

Dear all,
I've tried several times to build dlib, but waited more than 1 hour at face_recognition.cpp without seeing any progress. I redo it several times but still get stuck there. Can you help me with it?

@runt1m33rr0r
Copy link

@BachDoXuan you need to use the visual studio 2015 compiler(msvc-14.0), 14.1 is bugged. You also need at least 2GB RAM, because face_recognition.cpp takes a lot of memory during compilation(which could be the reason it takes so long).

@BachDoXuan
Copy link

I use VS CE 2017, 8GB RAM laptop. I use Windows 10 Pro but the windows is not activated. I have no idea what problem I have. Can you help me to install dlib?

@masoudr
Copy link
Author

masoudr commented Sep 29, 2017

@BachDoXuan I used MSVC-14 and haven't tested the 2017 version. Are you using the precompiled version of Boost or compiling it by yourself?
Remember that some of the steps in this tutorial are for MSVC-14 and if you want to use with other versions you need to modify them.
Could you provide the error log?

@BachDoXuan
Copy link

@masoudr @neutrinobomber Thank you very much for your helps. The screen doesn't have any error log. It just got stuck when building dlib at face_recognition.cpp, I waited for more than hour every time I got there. But currently when I use command "pip install face_recognition" directly, then it succeeds.

@masoudr
Copy link
Author

masoudr commented Sep 29, 2017

@BachDoXuan You are right, you can always use pip to install this package without any further work on windows. This tutorial is for the people who wanted to build dlib from source or do some configurations to it.

@davisking
Copy link

davisking commented Sep 29, 2017 via email

@loqpa
Copy link

loqpa commented Oct 4, 2017

Hey! I have a problem while following this tutorial.
My versions are:
Python 3.5.4
dlib 19.7
boost 1.65.1
(using "with cuda" and "with avx" options)

jpeg.lib(jdatadst.c.obj) : error LNK2019: unresolved external symbol _imp_ferror referenced in function term_destination [C:\Users\Loqpa\Downloads\dlib-master\dlib-master\tools\python\build\dlib.vcxproj]
jpeg.lib(jmemmgr.c.obj) : error LNK2019: unresolved external symbol __imp___stdio_common_vsscanf referenced in function vsscanf_l [C:\Users\Loqpa\Downloads\dlib-master\dlib-master\tools\python\build\dlib.vcxproj]
jpeg.lib(jmemansi.c.obj) : error LNK2019: unresolved external symbol imp_tmpfile referenced in function jpeg_open_backing_store [C:\Users\Loqpa\Downloads\dlib-master\dlib-master\tools\python\build\dlib.vcxproj]
C:\Users\Loqpa\Downloads\dlib-master\dlib-master\tools\python\build\Release\dlib.pyd : fatal error LNK1120: 3 unresolved externals [C:\Users\Loqpa\Downloads\dlib-master\dlib-master\tools\python\build\dlib
.vcxproj]

Any ideas how to fix it? I am up to trying everything you suggest:)

@masoudr
Copy link
Author

masoudr commented Oct 4, 2017

@loqpa Hi,
Are you using a precompiled version of boost with MSVC14?
Try to add these system environment variables too:
VS110COMNTOOLS C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Tools\
VS120COMNTOOLS C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\
VS110COMNTOOLS C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Tools\
VSSDK140Install C:\Program Files (x86)\Microsoft Visual Studio 14.0\VSSDK\
I don't know the exact cause of your problem but it seems that some of the library files are not recognized by dlib.

@loqpa
Copy link

loqpa commented Oct 6, 2017

@masoudr Hello!
I am compiling boost by myself (following steps 3-1... 3-4) and my system environment variables were already set the way you suggested.
Tried with boost 1.63, got the same error.
Any other ideas?
By the way, i am using Anaconda python, in case it matters.

@masoudr
Copy link
Author

masoudr commented Oct 6, 2017

@loqpa I used this method for the specified version of dependencies, so I am not sure if they work for other versions too.
As I know your problem is causing by missing some dll files on dlib's compile. I think you can try first submit your issue on dlib repository here, maybe @davisking have an answer to it and second use the exact procedure I mentioned here. I don't' know much about Anaconda try to exclude it.

@Klinsman21
Copy link

Does anyone have the link to download, Microsoft Visual Studio 2015 with C / C ++ Compiler

@masoudr
Copy link
Author

masoudr commented Oct 7, 2017

@Klinsman21 google is your friend :) try this.

@loqpa
Copy link

loqpa commented Oct 7, 2017

@masoudr what dlib version did you use? I can use precompiled version 19.4 without any problems but i am really curious about new(19.5+) cnn face_detector :)

@masoudr
Copy link
Author

masoudr commented Oct 8, 2017

@loqpa If you compile dlib from the source you can always use the latest features and besides of that you can customize the compilation for specific configuration like disable/enable AVX instruction, CUDA feature, etc. I used v19.6 but newer versions would work too. You can find new features on dlib's website in here.

@cmlyldz
Copy link

cmlyldz commented Oct 11, 2017

Can anybody help me ?
VC 2015
boost 1_65_1
dlib 19.7

libboost_python3-vc140-mt-s-1_65_1.lib(errors.obj) : fatal error LNK1112: module machine type 'x64' conflicts with target machine type 'X86' [D:\DEV\dlib-master\tools\python\build\dlib_.vcxproj]
1 Warning(s)
1 Error(s)
Time Elapsed 00:04:35.66
error: cmake build failed!

@masoudr
Copy link
Author

masoudr commented Oct 11, 2017

@cmlyldz You are trying to compile an X86 code on X64 compiler or vice-versa. Try to use VS2015 x86 Native Tools Command Prompt to compile dlib and remember that your python architecture must be same.

@cmlyldz
Copy link

cmlyldz commented Oct 12, 2017

@masoudr Thanks for answer. The problem was my python but there is no problem thanks to you.

@hepingtao
Copy link

@masoudr I have also encountered exactly the same problem as @cmlyldz . And I used VS2015 x86 Native Tools Command Prompt to compile dlib, but the problem didn't go.

@masoudr
Copy link
Author

masoudr commented Oct 13, 2017

@hepingtao Please give me more information about the exact version of your tools like python version?

@cmlyldz
Copy link

cmlyldz commented Oct 13, 2017

@hepingtao be careful while downloading scipy, numpy you have to download them x86 like others(if you want to use x86). Also python, boost and also dlib must compile on x86 also. If you did everything in an x86 compiler (or x64) there will be no error.

@008karan
Copy link

I have installed cmak and added to path but while installing dlib getting message to install cmak

@masoudr
Copy link
Author

masoudr commented Oct 15, 2017

@008karan If your CMake is successfully added, you can use cmake --version in cmd to verify that. I'm not sure if the problem will exist but put your complete error log here.

@shivamcreator
Copy link

You don't need to manually install dlib. I was able to install it with pip (through the pip install face_recognition command) after I had Boost and CMake installed.

Which leads me to my second point; your tutorial does not mention CMake at all. I have no idea what CMake actually does, so it may not be required, but if it does have something to do with simplifying the install process, you should add it to your tutorial.

hi!
I am not able to install dlib from pip command.
image

@masoudr
Copy link
Author

masoudr commented Aug 19, 2021

You don't need to manually install dlib. I was able to install it with pip (through the pip install face_recognition command) after I had Boost and CMake installed.
Which leads me to my second point; your tutorial does not mention CMake at all. I have no idea what CMake actually does, so it may not be required, but if it does have something to do with simplifying the install process, you should add it to your tutorial.

hi!
I am not able to install dlib from pip command.
image

As the error indicates, you need to install CMake and add it to your system PATH.

@alisharf
Copy link

تشغيل تثبيت setup.py لـ dlib ... خطأ
خطأ: خطأ في الأمر مع حالة الخروج 1:
الأمر: 'd: \ pythonpractice \ pictures \ scripts \ python.exe' -u -c 'import sys، setuptools، tokenize؛ sys.argv [0] = "" "" C: \ Users \ avalvi \ AppData \ Local \ Temp \ pip-install-2u4dltn8 \ dlib \ setup.py '"" "'؛ file = "" "" C: \ Users \ avalvi \ AppData \ Local \ Temp \ pip-install-2u4dltn8 \ dlib \ setup.py '"" ""؛ f = getattr (رمز مميز ، "" "" فتح " "" "، فتح) ( ملف ) ؛ كود = f.read (). استبدل ('" ""' \ r \ n '"" "'، '" ""' \ n '"" "')؛ f.close ()؛ exec (ترجمة (رمز ، ملف ، "" "" "
cwd: C: \ Users \ avalvi \ AppData \ Local \ Temp \ pip-install-2u4dltn8 \ dlib
الإخراج الكامل (74 سطرًا):
تشغيل التثبيت
قيد
التشغيل الذي يعمل على تشغيل build_py
package init ملف 'dlib_ init _.py' غير موجود (أو لا ملف عادي)
تشغيل build_ext
Building extension for Python 3.8.4 (tags / v3.8.4: dfa645a ، 13 يوليو 2020 ، 16:30:28) [MSC v.1926 32 bit (Intel)]
استدعاء إعداد CMake: 'cmake C: \ Users \ avalvi \ AppData \ Local \ Temp \ pip-install-2u4dltn8 \ dlib \ tools \ python -DCMAKE_LIBRARY_OUTPUT_DIRECTORY = C: \ Users \ avalvi \ AppData \ Local \ Temp \ pip-install- 2u4dltn8 \ dlib \ build \ lib.win32-3.8 -DPYTHON_EXECUTABLE = d: \ pythonpractice \ pictures \ scripts \ python.exe -DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE = C: \ Users \ avalvi \ AppData-install \ TEM8 \ d pipl build \ lib.win32-3.8 '

  • إنشاء لـ: Visual Studio 10 2010
    CMake Error في CMakeLists.txt: 3 (مشروع):

@alisharf
Copy link

If you want to install the dlib library, you need to install c++

@MarcioJrios
Copy link

MarcioJrios commented Oct 8, 2021

For anyone facing errors trying to install directly on windows, there is the option of using a WSL(Windows Subsystem for Linux), wich is a native VM implementation for windows. You can install normally the API like you would in a Linux machine, then you can acess it directly through Windows using VScode with the extension "Remote -WSL"(instuctions on how to do that are on the extension description itself).

wsl-example

Here is an example on it working perfeclty using Flask like if i am running it locally on windows.
Hope it helps anyone with problems related to Windows usage!

@gengyanlei
Copy link

gengyanlei commented Nov 19, 2021

environment: windows python3.8.8
you just need pip install dlib-19.19.0-cp38-cp38-win_amd64.whl,and pip install face_recognition
dlib whl提取码: 1sk6

@utkarshrocks
Copy link

You don't need to manually install dlib. I was able to install it with pip (through the pip install face_recognition command) after I had Boost and CMake installed.

Which leads me to my second point; your tutorial does not mention CMake at all. I have no idea what CMake actually does, so it may not be required, but if it does have something to do with simplifying the install process, you should add it to your tutorial.

Running setup.py install for dlib did not run successfully.
│ exit code: 1
╰─> [58 lines of output]
running install
running build
running build_py
package init file 'tools\python\dlib_init_.py' not found (or not a regular file)
running build_ext
Building extension for Python 3.10.2 (tags/v3.10.2:a58ebcc, Jan 17 2022, 14:12:15) [MSC v.1929 64 bit (AMD64)]
Invoking CMake setup: 'cmake C:\Users\Dell\AppData\Local\Temp\pip-install-ib3cgbg6\dlib_415ab045cd144cdabeed0215a5d6f304\tools\python -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\Users\Dell\AppData\Local\Temp\pip-install-ib3cgbg6\dlib_415ab045cd144cdabeed0215a5d6f304\build\lib.win-amd64-3.10 -DPYTHON_EXECUTABLE=C:\Users\Dell\AppData\Local\Programs\Python\Python310\python.exe -DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE=C:\Users\Dell\AppData\Local\Temp\pip-install-ib3cgbg6\dlib_415ab045cd144cdabeed0215a5d6f304\build\lib.win-amd64-3.10 -A x64'
-- Building for: Visual Studio 17 2022
-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19043.
-- The C compiler identification is unknown
-- The CXX compiler identification is MSVC 19.31.31104.0
CMake Error at CMakeLists.txt:14 (project):
No CMAKE_C_COMPILER could be found.

  -- Detecting CXX compiler ABI info
  -- Detecting CXX compiler ABI info - done
  -- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/bin/Hostx64/x64/cl.exe - skipped
  -- Detecting CXX compile features
  -- Detecting CXX compile features - done
  -- Configuring incomplete, errors occurred!
  See also "C:/Users/Dell/AppData/Local/Temp/pip-install-ib3cgbg6/dlib_415ab045cd144cdabeed0215a5d6f304/build/temp.win-amd64-3.10/Release/CMakeFiles/CMakeOutput.log".
  See also "C:/Users/Dell/AppData/Local/Temp/pip-install-ib3cgbg6/dlib_415ab045cd144cdabeed0215a5d6f304/build/temp.win-amd64-3.10/Release/CMakeFiles/CMakeError.log".
  Traceback (most recent call last):
    File "<string>", line 2, in <module>
    File "<pip-setuptools-caller>", line 34, in <module>
    File "C:\Users\Dell\AppData\Local\Temp\pip-install-ib3cgbg6\dlib_415ab045cd144cdabeed0215a5d6f304\setup.py", line 222, in <module>
      setup(
    File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\site-packages\setuptools\__init__.py", line 153, in setup
      return distutils.core.setup(**attrs)
    File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\distutils\core.py", line 148, in setup
      dist.run_commands()
    File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\distutils\dist.py", line 966, in run_commands
      self.run_command(cmd)
    File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\distutils\dist.py", line 985, in run_command
      cmd_obj.run()
    File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\site-packages\setuptools\command\install.py", line 61, in run
      return orig.install.run(self)
    File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\distutils\command\install.py", line 568, in run
      self.run_command('build')
    File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\distutils\cmd.py", line 313, in run_command
      self.distribution.run_command(command)
    File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\distutils\dist.py", line 985, in run_command
      cmd_obj.run()
    File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\distutils\command\build.py", line 135, in run
      self.run_command(cmd_name)
    File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\distutils\cmd.py", line 313, in run_command
      self.distribution.run_command(command)
    File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\distutils\dist.py", line 985, in run_command
      cmd_obj.run()
    File "C:\Users\Dell\AppData\Local\Temp\pip-install-ib3cgbg6\dlib_415ab045cd144cdabeed0215a5d6f304\setup.py", line 134, in run
      self.build_extension(ext)
    File "C:\Users\Dell\AppData\Local\Temp\pip-install-ib3cgbg6\dlib_415ab045cd144cdabeed0215a5d6f304\setup.py", line 171, in build_extension
      subprocess.check_call(cmake_setup, cwd=build_folder)
    File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 369, in check_call
      raise CalledProcessError(retcode, cmd)
  subprocess.CalledProcessError: Command '['cmake', 'C:\\Users\\Dell\\AppData\\Local\\Temp\\pip-install-ib3cgbg6\\dlib_415ab045cd144cdabeed0215a5d6f304\\tools\\python', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\\Users\\Dell\\AppData\\Local\\Temp\\pip-install-ib3cgbg6\\dlib_415ab045cd144cdabeed0215a5d6f304\\build\\lib.win-amd64-3.10', '-DPYTHON_EXECUTABLE=C:\\Users\\Dell\\AppData\\Local\\Programs\\Python\\Python310\\python.exe', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE=C:\\Users\\Dell\\AppData\\Local\\Temp\\pip-install-ib3cgbg6\\dlib_415ab045cd144cdabeed0215a5d6f304\\build\\lib.win-amd64-3.10', '-A', 'x64']' returned non-zero exit status 1.
  [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.

@galib937
Copy link

galib937 commented Nov 7, 2022

Hello good people! I was wondering if the encoding becomes properly trained if there is only 1 picture of each person or does there need to be at least more than 1 or something. Thats because when i have single image of different people the encoding after training , the recognition part gives a wrong detection. But whenever i have about 3 or more images of the same person being trained on the encodings, the recognition script gives the correct detection. Any input would be hugely appreciated

@galib937
Copy link

galib937 commented Nov 7, 2022

@loqpa I believe that was a known problem/bug with the dlib conda package on Windows specifically and not dlib itself

Hello good people! I was wondering if the encoding becomes properly trained if there is only 1 picture of each person or does there need to be at least more than 1 or something. Thats because when i have single image of different people the encoding after training , the recognition part gives a wrong detection. But whenever i have about 3 or more images of the same person being trained on the encodings, the recognition script gives the correct detection. Any input would be hugely appreciated

@faizannazir
Copy link

Clone dlib https://github.com/davisking/dlib.git
run
pip install dlib -e cloned repository folder location which contain setup.py file

@masoudr masoudr changed the title Windows Installation Tutorial Windows Installation Guide Mar 23, 2023
@MalshaDeZ
Copy link

The installation process worked perfectly without any issues for me. When I try pip list, face-recognition is there.

face-recognition                 1.3.0
dlib                           19.24.1
cmake                           3.26.3
python                         3.10.10

But when I try to import it in my project I get the error saying ModuleNotFoundError: No module named 'face_recognition'

can some one please help me
@masoudr, would love to hear your thoughts on this.

@masoudr
Copy link
Author

masoudr commented Apr 21, 2023

@MalshaDeZ I think your problem might be based on using the wrong environment, first you can double check your version with python -m pip freeze and look for the module. If the issue persists, try to use a virtual environment and install the module within it and then use it with your IDE.

@MalshaDeZ
Copy link

Hey @masoudr , thank you for getting back. Yes true that was the case. I am no able to import everything perfectly. But when run my code I get the error ImportError: DLL load failed while importing _dlib_pybind11: The specified module could not be found.
Can you tell me what I have done wrong here.

Following are my versions
cmake 3.22.6 dlib 19.24.1 face-recognition 1.3.0 python 3.10 pip 22.3.1

I would really appreciate any help on this.
Thank you in advance.

@MalshaDeZ I think your problem might be based on using the wrong environment, first you can double check your version with python -m pip freeze and look for the module. If the issue persists, try to use a virtual environment and install the module within it and then use it with your IDE.

@Akshitsingh-1
Copy link

Facing Same issue, was this solved

@faizannazir
Copy link

Facing Same issue, was this solved

#175 (comment)

@RazzaqAsad
Copy link

dlib installing issue using vs code window 10/11 can you please guide

ERROR:
(myenv) F:\PYTHON\FaceRecognition>pip install dlib
Collecting dlib
Using cached dlib-19.24.2.tar.gz (11.8 MB)
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: dlib
Building wheel for dlib (pyproject.toml) ... error
error: subprocess-exited-with-error

× Building wheel for dlib (pyproject.toml) did not run successfully.
│ exit code: 1
╰─> [78 lines of output]
running bdist_wheel
running build
running build_ext
:125: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
Building extension for Python 3.11.4 (tags/v3.11.4:d2340ef, Jun 7 2023, 05:45:37) [MSC v.1934 64 bit (AMD64)]
Invoking CMake setup: 'cmake C:\Users\asad4\AppData\Local\Temp\pip-install-mnx66irs\dlib_8e13c4c6f55945409bd78d369ace28f6\tools\python -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\Users\asad4\AppData\Local\Temp\pip-install-mnx66irs\dlib_8e13c4c6f55945409bd78d369ace28f6\build\lib.win-amd64-cpython-311 -DPYTHON_EXECUTABLE=F:\PYTHON\FaceRecognition\myenv\Scripts\python.exe -DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE=C:\Users\asad4\AppData\Local\Temp\pip-install-mnx66irs\dlib_8e13c4c6f55945409bd78d369ace28f6\build\lib.win-amd64-cpython-311 -A x64'
-- Building for: NMake Makefiles
CMake Error at CMakeLists.txt:5 (message):

    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


    You must use Visual Studio to build a python extension on windows.  If you
    are getting this error it means you have not installed Visual C++.  Note
    that there are many flavors of Visual Studio, like Visual Studio for C#
    development.  You need to install Visual Studio for C++.


    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!




  -- Configuring incomplete, errors occurred!
  Traceback (most recent call last):
    File "F:\PYTHON\FaceRecognition\myenv\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 353, in <module>
      main()
    File "F:\PYTHON\FaceRecognition\myenv\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 335, in main
      json_out['return_val'] = hook(**hook_input['kwargs'])
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "F:\PYTHON\FaceRecognition\myenv\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 251, in build_wheel
      return _build_backend().build_wheel(wheel_directory, config_settings,
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "C:\Users\asad4\AppData\Local\Temp\pip-build-env-6kb9dteu\overlay\Lib\site-packages\setuptools\build_meta.py", line 434, in build_wheel
      return self._build_with_temp_dir(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "C:\Users\asad4\AppData\Local\Temp\pip-build-env-6kb9dteu\overlay\Lib\site-packages\setuptools\build_meta.py", line 419, in _build_with_temp_dir
      self.run_setup()
    File "C:\Users\asad4\AppData\Local\Temp\pip-build-env-6kb9dteu\overlay\Lib\site-packages\setuptools\build_meta.py", line 341, in run_setup
      exec(code, locals())
    File "<string>", line 218, in <module>
    File "C:\Users\asad4\AppData\Local\Temp\pip-build-env-6kb9dteu\overlay\Lib\site-packages\setuptools\__init__.py", line 107, in setup
      return distutils.core.setup(**attrs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "C:\Users\asad4\AppData\Local\Temp\pip-build-env-6kb9dteu\overlay\Lib\site-packages\setuptools\_distutils\core.py", line 185, in setup
      return run_commands(dist)
             ^^^^^^^^^^^^^^^^^^
    File "C:\Users\asad4\AppData\Local\Temp\pip-build-env-6kb9dteu\overlay\Lib\site-packages\setuptools\_distutils\core.py", line 201, in run_commands
      dist.run_commands()
    File "C:\Users\asad4\AppData\Local\Temp\pip-build-env-6kb9dteu\overlay\Lib\site-packages\setuptools\_distutils\dist.py", line 969, in run_commands
      self.run_command(cmd)
    File "C:\Users\asad4\AppData\Local\Temp\pip-build-env-6kb9dteu\overlay\Lib\site-packages\setuptools\dist.py", line 1233, in run_command
      super().run_command(command)
    File "C:\Users\asad4\AppData\Local\Temp\pip-build-env-6kb9dteu\overlay\Lib\site-packages\setuptools\_distutils\dist.py", line 988, in run_command
      cmd_obj.run()
    File "C:\Users\asad4\AppData\Local\Temp\pip-build-env-6kb9dteu\overlay\Lib\site-packages\wheel\bdist_wheel.py", line 349, in run
      self.run_command("build")
    File "C:\Users\asad4\AppData\Local\Temp\pip-build-env-6kb9dteu\overlay\Lib\site-packages\setuptools\_distutils\cmd.py", line 318, in run_command
      self.distribution.run_command(command)
    File "C:\Users\asad4\AppData\Local\Temp\pip-build-env-6kb9dteu\overlay\Lib\site-packages\setuptools\dist.py", line 1233, in run_command
      super().run_command(command)
    File "C:\Users\asad4\AppData\Local\Temp\pip-build-env-6kb9dteu\overlay\Lib\site-packages\setuptools\_distutils\dist.py", line 988, in run_command
      cmd_obj.run()
    File "C:\Users\asad4\AppData\Local\Temp\pip-build-env-6kb9dteu\overlay\Lib\site-packages\setuptools\_distutils\command\build.py", line 131, in run
      self.run_command(cmd_name)
    File "C:\Users\asad4\AppData\Local\Temp\pip-build-env-6kb9dteu\overlay\Lib\site-packages\setuptools\_distutils\cmd.py", line 318, in run_command
      self.distribution.run_command(command)
    File "C:\Users\asad4\AppData\Local\Temp\pip-build-env-6kb9dteu\overlay\Lib\site-packages\setuptools\dist.py", line 1233, in run_command
      super().run_command(command)
    File "C:\Users\asad4\AppData\Local\Temp\pip-build-env-6kb9dteu\overlay\Lib\site-packages\setuptools\_distutils\dist.py", line 988, in run_command
      cmd_obj.run()
    File "<string>", line 130, in run
    File "<string>", line 167, in build_extension
    File "C:\Users\asad4\AppData\Local\Programs\Python\Python311\Lib\subprocess.py", line 413, in check_call
      raise CalledProcessError(retcode, cmd)
  subprocess.CalledProcessError: Command '['cmake', 'C:\\Users\\asad4\\AppData\\Local\\Temp\\pip-install-mnx66irs\\dlib_8e13c4c6f55945409bd78d369ace28f6\\tools\\python', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\\Users\\asad4\\AppData\\Local\\Temp\\pip-install-mnx66irs\\dlib_8e13c4c6f55945409bd78d369ace28f6\\build\\lib.win-amd64-cpython-311', '-DPYTHON_EXECUTABLE=F:\\PYTHON\\FaceRecognition\\myenv\\Scripts\\python.exe', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE=C:\\Users\\asad4\\AppData\\Local\\Temp\\pip-install-mnx66irs\\dlib_8e13c4c6f55945409bd78d369ace28f6\\build\\lib.win-amd64-cpython-311', '-A', 'x64']' returned non-zero exit status 1.
  [end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for dlib
Failed to build dlib
ERROR: Could not build wheels for dlib, which is required to install pyproject.toml-based projects

[notice] A new release of pip is available: 23.1.2 -> 23.2.1
[notice] To update, run: python.exe -m pip install --upgrade pip

@progmars
Copy link

@RazzaqAsad

I solved it in a clean, standalone Python environment using a prebuilt dlib whl:

#175 (comment)

@Akshitsingh-1
Copy link

Akshitsingh-1 commented Aug 21, 2023

@RazzaqAsad

I solved it in a clean, standalone Python environment using a prebuilt dlib whl:

#175 (comment)

can you please give the link from where to download and how to setup

@progmars
Copy link

@Akshitsingh-1 My comment here has the full instructions:
#175 (comment)

The crucial part is that it worked only with Python 3.6 and not newer because I could not find precompiled dlib for newer Python versions.
Then I could install the prebuilt wheel from

pip install https://files.pythonhosted.org/packages/0e/ce/f8a3cff33ac03a8219768f0694c5d703c8e037e6aba2e865f9bae22ed63c/dlib-19.8.1-cp36-cp36m-win_amd64.whl

@faizannazir
Copy link

@RazzaqAsad
I solved it in a clean, standalone Python environment using a prebuilt dlib whl:
#175 (comment)

can you please give the link from where to download and how to setup
@Akshitsingh-1
Clone dlib https://github.com/davisking/dlib.git
run
pip install dlib -e cloned repository folder location which contain setup.py file

@progmars
Copy link

@faizannazir - if you clone dlib git, won't it attempt to compile it during install, leading to the same problems (requiring the right compilation tools etc.)? It's simpler to just download a pre-built dlib.

@faizannazir
Copy link

@faizannazir - if you clone dlib git, won't it attempt to compile it during install, leading to the same problems (requiring the right compilation tools etc.)? It's simpler to just download a pre-built dlib.

It will compile when you run given pip command with no error

@Mehranmv
Copy link

im installed face_recognition_models but getting the error again !
how can i fc this?
image

@mhediehloo
Copy link

install dlib in windows is very easy. It is explained in the link below :
https://m.youtube.com/watch?v=xXbouOlAyoo

https://m.youtube.com/watch?v=BUu6hrcYI_c

@olstice
Copy link

olstice commented Apr 18, 2024

Hi, I've successfully installed and tested this tool on my Windows 10 machine, and I'm writing a simple procedure to install it. It may be useful for some people to try to use this tool on a Windows machine.

IMPORTANT: Actually, this project has been done for Linux systems, especially dlib. In my tests, the performance of this tool in Windows 10 was about a quarter compared to Ubuntu, built with the same specs. But I haven't seen any difference between these two in other subjects.

Read First: The new version of dlib doesn't need Boost anymore, so you can skip it. Remember that you still need to meet the following requirements. Requirments: (I've used this tutorial with these tools installed on Windows 10, but the newer versions may work too.)

1. Microsoft Visual Studio 2015 (or newer) with C/C++ Compiler installed. (Visual C++ 2015 Build Tools didn't work for me, and I got into problems in compiling `dlib`)

2. Of course `Python3` (I used `Python3.5 x64` but the other versions may work too)

3. [`CMake`](https://cmake.org/download/) for windows and add it to your system environment variables.

4. (**ONLY FOR** older versions of `dlib`) `Boost` library version 1.63 or newer. Also, you can use precompiled binaries for specific MSVC you have, but I don't suggest. (I've included the compiling procedure of `Boost` in this tutorial)

Installation: Easy installation: Just install dlib and face_recognition (not always on the newest version): pip install dlib and then pip install face_recognition.

Manual installation:

1. Download and install `scipy` and `numpy+mkl` (must be mkl version) packages from [this link](http://www.lfd.uci.edu/~gohlke/pythonlibs/) (all credits goes to Christoph Gohlke). Remember to grab the correct version based on your current Python version.

2. Download `Boost ` library source code or binary release for your current MSVC from [this link](https://sourceforge.net/projects/boost/files/).

3. If you downloaded the binary version skip to step 4 else, follow these steps to compile and build `Boost` by yourself:
   3-1. Extract the `Boost` source files into `C:\local\boost_1_XX_X` (X means the current version of `Boost` you have)
   3-2. Create a system variable with these parameters:
   Name: `VS140COMNTOOLS`
   Value: `C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\` (or any path where you have installed MSVC)
   3-3. Open Developer Command Prompt for Visual Studio and go to the current directory of `Boost` extracted and try these commands to compile `Boost`:
   `bootstrap`
   `b2 -a --with-python address-model=64 toolset=msvc runtime-link=static`
   3-4. If you successfully compile `Boost`, it should create compiled files in `stage` directory.

4. (If you have already compiled `Boost` skip this step) If you already download the binary release, extract the contents to `C:\local\boost_1_XX_X`

5. Grab the latest version of `dlib` from [this repo](https://github.com/davisking/dlib) and extract it.

6. Go to `dlib `directory and open cmd and follow these commands to build `dlib`: (remember to replace XX with the current version of `Boost` you have)
   `set BOOST_ROOT=C:\local\boost_X_XX_X`
   `set BOOST_LIBRARYDIR=C:\local\boost_X_XX_X\stage\lib`
   `python setup.py install --yes USE_AVX_INSTRUCTIONS` or `python setup.py install --yes USE_AVX_INSTRUCTIONS --yes DLIB_USE_CUDA`

7. Now, you can use `import dlib` without any problem in your python script.

8. You can also check the current version of `dlib` with `pip show dlib`.

9. Now, install `face_recognition` with `pip install face_recognition`.

10. Enjoy!

Finally, I need to say thanks to @ageitgey and @davisking for their awesome work.

Your instructions make no sense to me on this part going on 3-3. Open Developer Command Prompt for Visual Studio and go to the current directory of Boost extracted and try these commands to compile Boost:
bootstrap
b2 -a --with-python address-model=64 toolset=msvc runtime-link=static

i cant go past this because i still dont understand this

@cc1287
Copy link

cc1287 commented Apr 18, 2024

I can install dlib and face-recognition, but when running the sample project, the program reported an error and some files were missing. Where should I complete these files? (Note: My computer is Windows 10, Python version 3.9.7)
Thank you for your help.

RuntimeError: Unable to open D:\***\python\lib\sitepackages\face_recognition_models\models\shape_predictor_68_face_landmarks.dat

demo:

import face_recognition
import cv2
import numpy as np

# This is a demo of running face recognition on live video from your webcam. It's a little more complicated than the
# other example, but it includes some basic performance tweaks to make things run a lot faster:
#   1. Process each video frame at 1/4 resolution (though still display it at full resolution)
#   2. Only detect faces in every other frame of video.

# PLEASE NOTE: This example requires OpenCV (the `cv2` library) to be installed only to read from your webcam.
# OpenCV is *not* required to use the face_recognition library. It's only required if you want to run this
# specific demo. If you have trouble installing it, try any of the other demos that don't require it instead.

# Get a reference to webcam #0 (the default one)
video_capture = cv2.VideoCapture(0)

# Load a sample picture and learn how to recognize it.
obama_image = face_recognition.load_image_file("obama.jpg")
obama_face_encoding = face_recognition.face_encodings(obama_image)[0]

# Load a second sample picture and learn how to recognize it.
# biden_image = face_recognition.load_image_file("biden.jpg")
# biden_face_encoding = face_recognition.face_encodings(biden_image)[0]

# Create arrays of known face encodings and their names
known_face_encodings = [
    obama_face_encoding,
    # biden_face_encoding
]
known_face_names = [
    "Barack Obama",
    # "Joe Biden"
]

# Initialize some variables
face_locations = []
face_encodings = []
face_names = []
process_this_frame = True

while True:
    # Grab a single frame of video
    ret, frame = video_capture.read()

    # Only process every other frame of video to save time
    if process_this_frame:
        # Resize frame of video to 1/4 size for faster face recognition processing
        small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25)

        # Convert the image from BGR color (which OpenCV uses) to RGB color (which face_recognition uses)
        rgb_small_frame = small_frame[:, :, ::-1]
        
        # Find all the faces and face encodings in the current frame of video
        face_locations = face_recognition.face_locations(rgb_small_frame)
        face_encodings = face_recognition.face_encodings(rgb_small_frame, face_locations)

        face_names = []
        for face_encoding in face_encodings:
            # See if the face is a match for the known face(s)
            matches = face_recognition.compare_faces(known_face_encodings, face_encoding)
            name = "Unknown"

            # # If a match was found in known_face_encodings, just use the first one.
            # if True in matches:
            #     first_match_index = matches.index(True)
            #     name = known_face_names[first_match_index]

            # Or instead, use the known face with the smallest distance to the new face
            face_distances = face_recognition.face_distance(known_face_encodings, face_encoding)
            best_match_index = np.argmin(face_distances)
            if matches[best_match_index]:
                name = known_face_names[best_match_index]

            face_names.append(name)

    process_this_frame = not process_this_frame


    # Display the results
    for (top, right, bottom, left), name in zip(face_locations, face_names):
        # Scale back up face locations since the frame we detected in was scaled to 1/4 size
        top *= 4
        right *= 4
        bottom *= 4
        left *= 4

        # Draw a box around the face
        cv2.rectangle(frame, (left, top), (right, bottom), (0, 0, 255), 2)

        # Draw a label with a name below the face
        cv2.rectangle(frame, (left, bottom - 35), (right, bottom), (0, 0, 255), cv2.FILLED)
        font = cv2.FONT_HERSHEY_DUPLEX
        cv2.putText(frame, name, (left + 6, bottom - 6), font, 1.0, (255, 255, 255), 1)

    # Display the resulting image
    cv2.imshow('Video', frame)

    # Hit 'q' on the keyboard to quit!
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

# Release handle to the webcam
video_capture.release()
cv2.destroyAllWindows()

@SedatUygur
Copy link

In step 6, you can use set flag instead of yes like below. because --yes options are on by default.

python setup.py install --set USE_AVX_INSTRUCTIONS=1 --set DLIB_USE_CUDA=1

@Sebastian-113
Copy link

im installed face_recognition_models but getting the error again ! how can i fc this? image
me2,how to solve this problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests